2

I am building an edit in place listView. That is, the user is looking at a list of TextView items. Then the user touches one, indicating he'd like to edit it. The selected item is now shown as an EditText, in the same ListView as the other TextView items.

After this, the soft keyboard is shown, but the EditText has actually lost focus because of all the redrawing. I've got a handle on the EditText in SimpleCursorAdapter.getView(). But, calling EditText.requestFocus() is futile unless I can be sure the EditText is there on the screen.

In which method of which class will I be able to execute something like, getListView().findItemById(n).requestFocus(); ?

Thank you very much.

Harry
  • 61
  • 8
  • Take a look at `View.OnAttachStateChangeListener` and http://developer.android.com/reference/android/view/ViewTreeObserver.html – Simon Oct 18 '12 at 20:34

1 Answers1

0

You can execute

 getInstrumentation().waitForIdleSync()

to wait for all UI events.

  • Thanks for the idea. I am not trying that right now for two reasons. Instrumentation appears to be meant for testing, which is not what I'm up to right now. And I would be afraid that I'll be writing code to handle every case in which I enter that block of code, when only one case interests me. And I wrong in my thnking? – Harry Oct 19 '12 at 20:32
  • Actually, now I think I see what you mean. But, I can't getInstrumentation()! I've added instrumentation to the manifest. What else do I have to do, please. – Harry Oct 21 '12 at 17:52
  • Yes, this class is for testing, but maybe you can use it anyway. http://developer.android.com/reference/android/test/InstrumentationTestCase.html – Nahuelistico Oct 23 '12 at 18:35