I've got a simple form that I am adding a 'reset; button to, that I'd like to have reset all of the form inputs when clicked. I can do this easily with a setOnClickListener()
and then resetting the EditText
fields manually, but just wonde开发者_如何学JAVAred if there was some built-in construct to handle form resets, like in HTML.
Thanks
I am afraid you have to do it the hard way by handling the button click Listener and one by one resetting each field.
As PravinCG said you have to do it in the hard way..
Another Way
:
Just a Try ( Dont know about performance issues)
You can reload the same Activity.
public void reload() {
Intent intent = getIntent();
overridePendingTransition(0, 0);
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
overridePendingTransition(0, 0);
startActivity(intent);
}
Code Copied From This Discussion:
How do I restart an Android Activity
That depends on the type of elements you have in the form.
One idea would be to set the default value in each element's tag property. Group all the elements under 1 groupview. When the user clicks the reset button, loop through all the elements inside the groupview and set their text value to the tag value.
finish();
startActivity(new Intent(MyActivity.this, MyActivity.class));
...and you'r done (kinda hackish, I know) !
精彩评论