Featured post

Displaying Multiple Fragments in a single Activity

Friday, 30 October 2015

Displaying the Name and Age of the user(Contd..)

Demo 3(Contd)

This is the business logic of the Demo3

package com.findandroidhub.demo3;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity
{

private EditText t1,t2;
private Button b;
private TextView tv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
t1=(EditText)findViewById(R.id.editText1);
t2=(EditText)findViewById(R.id.editText2);
b=(Button)findViewById(R.id.button1);
tv=(TextView)findViewById(R.id.display);

b.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {

String name=t1.getText().toString();
int age=Integer.parseInt(t2.getText().toString());

tv.setText("Your details are:"+"\n"+"Name: "+name+"\n"+"Age: "+age);

}
});
}

}

No comments:

Post a Comment