Search code examples
androidlistviewbuttonandroid-edittextback

Android - Physical Back Button on TextEdit erases content


I have a ListActivity with an EditText and a ListView. Content of the ListView changes according to the EditText content. I do the following steps:

1) Fill in something in the EditText

2) Consequently the Listview changes (properly)

3) I scroll the listview

4) I press the back button

At this point I expect to get back to the previous activity, while i happens that the EditText gets erased and consequently the ListView empty.

Is there a way to tell the EditText not to erase itself when Back Button is pressed?

Thanks a lot.

G


Solution

  • I just want the activity to finish whenever i press back button. Doesn't matter what i was doing and which object had the focus

    Here's how you can force a finish of the Activity when back is pressed...

    @Override
    public void onBackPressed() {
        finish();
    }