I will answer my own question here as I finally got it sorted... Hope
it can be useful for anybody else.

Using the setOnItemSelectedListener and onItemSelected is not needed
for this purpose. The solution was in the xml:

In the row TextView:

<TextView>
   android:id="@+id/label"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:textColor="#000000"
   android:padding="4px"
   android:background="@drawable/clickablelistitem"
/>

Then, in clickablelistitem.xml:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android";>
   <item   android:state_selected="true" android:drawable="@drawable/
background_white"/>
   <item   android:state_pressed="true" android:drawable="@drawable/
background_selected"/>
   <item   android:state_focused="true" android:drawable="@drawable/
background_white"/>
   <item   android:drawable="@drawable/background_white"/>
</selector>

where background_white.png is a 10x10 pixel white background, and
background_selected.png is a 10x10 pixel with selected color
background. I guess it could be achieved using a color definition as
well but at least it works now.

Also, remember to set android:listSelector="@android:color/
transparent" on the actual ListView.

However - I am still not able to catch onItemSelected - but live
happily without it so far.

Chris

On 3 Sep, 08:01, chrisoz <[email protected]> wrote:
> Thanks danny,
>
> what I am trying to achieve here is to change the background color of
> the selected list item (list items have a white background colour).
> Like you I am able to call onItemClick (or rather, onListItemClick),
> but not onItemSelected. Now, it is not possible to see which list item
> is selected.
>
> Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to