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
2010-07-16 09:27:09
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
2010-07-16 09:29:11
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
2010-07-16 09:31:39
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
2010-07-16 09:44:31
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
2010-07-16 10:39:23
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">
<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
2010-07-17 10:11:11