The app I've created just shows what users have typed in the EditText
.
This is the onCreate
method of its MainActivity
:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText input = (EditText) findViewById(R.id.input);
final TextView output = (TextView) findViewById(R.id.output);
final Editable input_editable = (Editable) input.getText();
final Button show = (Button) findViewById(R.id.show);
final Button reset = (Button) findViewById(R.id.reset);
show.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String text = input_editable.toString();
output.setText(text);
}
});
reset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
input_editable.clear();
}
});
}
The problem is this:
When i run the app, everything works fine:
- I type for eg "foo" and click "show" button, it shows "foo",
- When I click "reset" everything is resetted,
- Retype "bar", then it shows "bar". Nice!
But, when I just change the line
input_editable.clear();
to this
input.setText("");
then this happens after starting the app:
- I type for eg "foo" and click "show" button, it shows "foo",
- When I click "reset" everything seems to be resetted,
- Retype "bar", then "foo" is still there after clicking "show"
Why?
Thanks