I have an EditText where the user enters a name and I want this name to be assigned to a string variable for later use.
EditText et=(EditText)findViewById(R.id.editText1);
final String value=et.getText().toString();
Button b=(Button)findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
TextView tv=(TextView)findViewById(R.id.textView2);
tv.setText(value);
}
});
This is the code I am using. I enter some text in editText and when I click the button, the textView should display content in edittext. But when I click the button the textview becomes invisible i.e. it's having null value.