5

I have ListActivity with custom items, where every item has it's own TextEdit. Taping on any of them brings IME keyboard up and it causes ListView to be resized. So EditText, which recently received focus by tap looses it. Second tap is required to put it focused or sure. It happens only when I have move than 1 items in the list.

Is there any way to open IME and keep focus on EditText by only one tap?

dykzei eleeot
  • 169
  • 2
  • 6
  • 2
    As I suppose Android UI guidelines in general do not recommend using active controls, that can acquire focus and input in every list item. So I'm trying to cheat it. So far explicit focus setting with requestFocus on particular EditText doesn't help as adaptor remaps every item after ListView.onSizeChanged, so I consider adapter remap is the source of focus lost. – dykzei eleeot Jan 17 '11 at 06:10

2 Answers2

0

I solved this by storing the tapped EditText in a variable and requesting focus on it after a delay. It's a hack, but sometimes Android requires hacks.

Handler handler = new Handler();
handler.postDelayed(new Runnable() {
    public void run() {
        EditText editText = getListAdapter().tappedEditText;
        if (editText != null) {
            editText.requestFocus();
        }
    }
}, 100);
Quentamia
  • 3,244
  • 3
  • 33
  • 42
0

Do you want the list to be resized? Can you override the ListView.onSizeChanged and consume it instead of "bubbeling" it to super.onSizeChanged (assuming your assumption on the error source is correct)?

dbm
  • 10,376
  • 6
  • 44
  • 56
  • I did override - it doesn't help, as remapping in adapter happens after resize is done, obviously is't because ListView invalidates. Now I'm working on making list of TextViews with ability to edit item by tap on a new screen... – dykzei eleeot Jan 17 '11 at 22:38
  • You could, of course, show a Dialog with a TextEdit within when taping on a list item. Dialogs tend to belong to the same Activity they were started from and they position themselves right above the parent Activity without completely hiding it. This way you also get a visual indication of the fact that you haven't left the actual Activity. Maybe this link could be of help: http://groups.google.com/group/android-beginners/browse_thread/thread/efdfb8c7e24fee93?pli=1 – dbm Jan 18 '11 at 14:31
  • I've just realized that having dialog or another dedicated activity for editing list item entry is probably native official way of android GUI approach. – dykzei eleeot Jan 19 '11 at 05:29