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?
comment out the line
editText2.setText(m.getND());
and see if it set editText2 to "empty" - my guess is m.getND() is returning null
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..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.