Jeremy Edwards
Jeremy Edwards

Reputation: 14740

Android ListView partial pressable areas

I would like to create a ListView item layout where I can touch certain portions of a line item. This is similar to the behavior of the 2.0's Contacts Call Log where I can click on the green phone logo to initiate a call or click on the incoming call details to get more information about the contact.

I don't need a behavior only implementation. I already know to bind OnClickListeners to the portions of the line items where I want to capture the press. My real issue is that the UI doesn't react properly in certain cases when a user press against a certain area of the screen. IE: if they clicked the green phone icon, only the box around the phone will highlight as pressed. Where as pressing the name will highlight that area.

I looked at the source code for the contacts app but it's very complicated and I was able to get some success I have issues where the source code is referencing Drawables and resources that aren't exposed in the SDK itself.

I would like a reasonable implementation that does not rely on internal resource of android. Or at least some pointers in the right direction.

I'm looking for a solution that works with not only pressing but the 5-way directional keypad as well.

Here's a graphic that shows what I'm talking about.

Android Call Log
(source: the-gadgeteer.com)

Upvotes: 4

Views: 1907

Answers (1)

Christopher Orr
Christopher Orr

Reputation: 111565

It just looks like when setting up each list row in the newView method they set an onClickListener for the green call_icon. While binding the view the telephone number is added to the call_icon by way of the View.setTag() method.

Then, in the onClick handler, the phone number gets pulled and the phone call Intent is fired.

All other presses on the list row get handled by the usual way — the onListItemClick method.

Upvotes: 3

Related Questions