MergeAdapter & focus

92 views
Skip to first unread message

MarcoAndroid

unread,
Aug 2, 2009, 10:38:04 AM8/2/09
to cw-android
Hi Mark,

I've been integrating the MergeAdapter in my app, with on top an
inputbox + searchbutton & search results below.
It works almost perfect, except that I'm losing focus on my inputbox
(edittext). Here's what I did:

In the MergeAdapterDemo I did this after creating the MergeAdapter:

// Add search box (relativelayout with textviews, edittexts and linear
layouts)
LayoutInflater vi = (LayoutInflater) getSystemService
(Context.LAYOUT_INFLATER_SERVICE);
View v = vi.inflate(R.layout.search_box, null);
adapter.addView(v);

That shows the searchbox above the firstlist + button + secondlist
from the demo, as expected.

What is not ok then:
When I click the edittext box to enter some searchcriteria, it gets
focus for a splitsecond, then keyboard pops up as excepted. But then
the edittext I just clicked on looses its focus! I have to click it
again to be able to enter its data. This does not happen using the
searchbox in a regular way (i.e w/o the MergeAdapter).

Any idea on how to fix this?

PS: I also see that the default focus in the emulator is on the first
entry of the first list, not on the first inputbox. Maybe related?

Regards,
Marco


Mark Murphy

unread,
Aug 2, 2009, 10:59:24 AM8/2/09
to cw-an...@googlegroups.com
MarcoAndroid wrote:
> I've been integrating the MergeAdapter in my app, with on top an
> inputbox + searchbutton & search results below.
> It works almost perfect, except that I'm losing focus on my inputbox
> (edittext).

I haven't tested MergeAdapter with anything focusable, as I tend to
avoid focusable items in lists where possible.

> When I click the edittext box to enter some searchcriteria, it gets
> focus for a splitsecond, then keyboard pops up as excepted. But then
> the edittext I just clicked on looses its focus! I have to click it
> again to be able to enter its data. This does not happen using the
> searchbox in a regular way (i.e w/o the MergeAdapter).
>
> Any idea on how to fix this?

Off the top of my head, I don't have a simple solution. Adapters don't
know anything about the focus, so I do not know how the Adapter could be
affecting the focus.

For this case, will ListView#addHeaderView() suffice? Or does it give
the same results? If the latter, then I think this is more of a issue of
having focusable items in a ListView, more so than MergeAdapter
specifically.

> PS: I also see that the default focus in the emulator is on the first
> entry of the first list, not on the first inputbox. Maybe related?

Possibly. There are some fairly conventional tricks for dealing with
focusable items in a ListView that have been posted (Romain Guy has
posted them a couple of times). Off the top of my head, I forget what
they were, but you could try those.

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android App Developer Books: http://commonsware.com/books.html

Reply all
Reply to author
Forward
0 new messages