0

What I would like to do is indicate selection of a list item by changing the border only, and only changing it during the selection. Afterwords normal width and color. I want to keep my listview image in the background as the background for all the list items. So I don't want to see anything different in the background when the list view item is selected. Just want to see some temporary highlighting of the border. How could this be done. Thanks

Androider
  • 21,125
  • 36
  • 99
  • 158

2 Answers2

0

You can use custom listview layout for each item. Use 2 layouts (one linear layout inside another for example.) inner one slightly smaller than outer one. Initily keep the background color for both the layouts same. On click event change the background for outer layout using selector. Thus giving you the border highlight effect as expected.

Tushar Vengurlekar
  • 7,649
  • 8
  • 33
  • 48
  • Won't work because I am using a transparent background. What I want is to just alter the divider above and below. Thats all i am trying to do. How could I get a hold of these dividers and modify there size and color? Thanks – Androider Feb 21 '11 at 12:42
-1

Why don't you try to use 9-patch drawables witch custom selector. More info about 9 patch drawables http://developer.android.com/guide/developing/tools/draw9patch.html

Mojo Risin
  • 8,136
  • 5
  • 45
  • 58
  • Please read the question, this is about a transparent background, and not wanting to draw an image to the background at all. – Androider Feb 21 '11 at 11:37
  • Transparent background only with border ? – Mojo Risin Feb 21 '11 at 11:41
  • I will credit your answer if you can explain how to modify just above, below divider of selected item, like highlighting them on selection. Thanks – Androider Feb 21 '11 at 11:41
  • Yes. Exactly, What I am trying to do is leave transparent background which is achieved by setting android:cacheColorHint="#00000000" android:listSelector="#00000000" – Androider Feb 21 '11 at 11:50
  • So the question is given a selection how to highlight the divider above and below the selected item. – Androider Feb 21 '11 at 11:50
  • I want to show selection only based on the the two dividers being hightlighted. – Androider Feb 21 '11 at 11:51
  • No i think you should add custom selector. And to use 9-patch drawables with this selector and you have to make your drawables to be transparent inside and to have only the border you want. – Mojo Risin Feb 21 '11 at 11:53
  • how would you set a custom selector? How could a custom selector reference the 9-patch. Please be specific. Thanks – Androider Feb 21 '11 at 12:04
  • Define and set custom selector like this - http://stackoverflow.com/questions/4989908/selector-for-my-custom-list-view. Here is tutorial how to create 9 patch drawables http://www.android10.org/index.php/articlesother/279-draw-9-patch-tutorial. Now you have to use the 9 patch drawables in you selector as backgrounds for the different states – Mojo Risin Feb 21 '11 at 12:09
  • won't work because I am using transparent background. What I would like to know is just this: how do I get a hold of the divider above and below the selected listitem and modify/restore the properties of these two dividers to create a selection effect? – Androider Feb 21 '11 at 12:44
  • i guess this [Link](http://www.geekmind.net/2009/10/android-custom-listview-selector.html) is what Mojo Risin was talking about. – Samuel Mar 17 '11 at 05:21