cavallo
cavallo

Reputation: 4414

How to clear the search text in the edit text on back press in android

i have a edit text and when i search the results are fine. but if i back press and come back the result remain the same, rather how to clear the edit text and load the fresh list.. help me please thanks in advance.

Upvotes: 0

Views: 1116

Answers (2)

user419190
user419190

Reputation:

public void onResume() {
          super.onResume();
           searchBox.setText("");
}

try this one

Upvotes: 0

Graeme
Graeme

Reputation: 25864

You should check if the activity is being reloaded by checking the Bundle in onCreate():

In the Activity containing the EditText you want to blank when you go back to it you need this:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    EditText searchBox = ...
    if(savedInstanceState != null) {
        searchBox.setText("");
    }

Upvotes: 2

Related Questions