I want to check if the text in some EditText
is changed, after user clicks some Button
. But View#isDirty
seems not to return the correct state of the EditText
if called inside onClick
. For instance, I wrote something like this:
public class MainActivity extends Activity {
EditText editText;
Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
button = (Button) findViewById(R.id.f);
editText = (EditText) findViewById(R.id.e);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println((editText.isDirty() ? "is dirty" : "is clean"));
}
});
}
}
before i make any change to the editText, it outputs is clean
, as expected. But the same is clean
is printed even after I write something in editText.
When will isDirty
be called? And is it the correct way to do this at all?
Update:
I also want to check if some Switch
and Spinner
values are changed. Is isDirty()
the correct way to do this?