views:

54

answers:

2

I have a linear layout in which each row is inflated programatically and I want the rows to behave like the ListView when clicked on. That is, I want the row to highlight in the exact same way/colour that the default ListView does. How would I go about doing this?

+1  A: 

This might be a good place to start looking.

Although, i would advise you to use the ListView itself, rather than implementing it again.

st0le
I would use the ListView however I need it NOT to scroll and place it inside a ScrolView and that doesn't seem possible(??)...So I ended up trying to implement my own ListView of sort using a LinearLayout.
Kman
and thanks or the link...but would it be possible to reference and use the default ListViews selector element rather than create my own?
Kman
you could possibly search for the XML inside the Android Source Code...and just copy it over? i'm not sure if you refer the existing selector,otherwise.
st0le
Sorry couldnt figur out which one the ListView uses...anyways I tried creating my own but it doesnt seem to be working but am having problems:I want the whole LinearLayout to highlight so what attribute do I set as the colour selector? I tried using textColour but that doesn't seem to work and background makes it crash since I can only set a drawable or single colour as a background :S
Kman
A: 

Ok iv finally figured out how to do this...basically it is done using a selector like the color selector linked by st0le except instead of 'color' use a drawable for the states and you can refer to the default list drawable that is used in ListView by this:

<selector xmlns:android="http://schemas.android.com/apk/res/android"&gt;
<item android:state_pressed="true"
    android:drawable="@android:drawable/list_selector_background" />      
</selector>

and using this xml as the background for my View.

All the public default drawables can be found here: http://developer.android.com/reference/android/R.drawable.html

Kman