0

Is there a way to detect when the keyboard is about to be presented in Android?

My problem is that I have a ListView with EditTexts in it. When the keyboard is about to be presented, these are quite often redrawn, causing an EditText that was JUST tapped to lose focus and require an extra tap.

My proposed solution is to monitor when the keyboard is about to be shown, check to see which view currently has focus, then after the keyboard is done being shown, restore focus to that view.

However, I have no idea how to detect when the keyboard is "about to be shown" in Android. How would I do this?

(I would also accept an alternative answer that addresses my actual problem: EditText losing focus when keyboard is displayed)

MikeS
  • 3,853
  • 6
  • 31
  • 50

1 Answers1

1

You could do it the other way, create an unique OnFocusChangedListener myListener and set it to all your EditTexts and put a switch inside and store which is the last view getting/losing focus

MariusBudin
  • 1,287
  • 1
  • 10
  • 20
  • I thought of this, but the main problem is still knowing when the keyboard is about to be displayed. For example, focus could change (lose focus) because the keyboard gets displayed, OR focus could chance (lose focus) because another EditText was tapped. – MikeS Mar 12 '13 at 14:26
  • I was gonna say check if keyboard is showing in the focuschanged but investigating a little, it's not as simple as might think: http://stackoverflow.com/questions/2150078/how-to-check-visibility-of-software-keyboard-in-android – MariusBudin Mar 12 '13 at 14:29