0

I have multiple different listView adapters. Each listView adapter has some editText. When user is editing editText, the soft keyboard will show up. I want to update the text in editText when user hit BACK button to dismiss keyboard.

For updating info, I will need to know which adapter class is handling, which position of this editText is editing, and the content of text.

I have googled all the possible solutions. There is one to set up a custom editText class, and override OnKeyPreIme function. This solution couldn't get me all the infomation i want above.

Please suggest me some way to intercept BACK button I could implement in the adapter class. Or Which I could easily get the info I want to update.

Kevin Science
  • 283
  • 4
  • 17

1 Answers1

0

You can use onBackPressed() from the Activity to detect when the user has pressed the back button.

It's not clear what logic you're really after; but the general pattern would be is that when you capture the event, you should be able to assess the states of all the EditText resources that can be accessed by your Activity. You can use setText() and getText() to establish the bespoke functionality you're describing.

You may need to determine whether the soft keyboard is open or not when you handle the back button press; i.e, whether you wish to update the fields at all. This solution describes a useful mechanism for doing so.

Mapsy
  • 3,749
  • 1
  • 30
  • 42