Reputation: 23
I have the following code, which should change the value of an EditText
field when the button is clicked...
public class ConvertActivity extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button b1 = (Button) findViewById(R.id.b1);
b1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
b1.setEnabled(true);
EditText editText2 = (EditText)findViewById(R.id.editText2);
String editTextStr2 = editText2.getText().toString();
editText2.setText("empty");
}
});
}
}
However, when I click the button, the text doesn't change. Is there something wrong with my code?
Upvotes: 0
Views: 961
Reputation: 1134
comment out the line
editText2.setText(m.getND());
and see if it set editText2 to "empty" - my guess is m.getND() is returning null
Upvotes: 2
Reputation: 8079
You are enabling the button in onClick of that button...that means it doesn't function i think.. because earlier it was not enabled..put
b1.setEnabled(true);
in onCreate part.. not in onClick..
Upvotes: 1