android - The highligted row in ListView doesn't remain highlighted after scrolling -


i have created listview simplecursoradapter , made highlight when of item clicked on following code.

<selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:state_selected="true" android:drawable="@color/blue" />   <item  android:drawable="@color/white" />  </selector> 

and on item selected have done below.

list = (listview) view.findviewbyid(android.r.id.list); adapter = new simplecursoradapter(getactivity(), r.layout.title_intro_list, articlecur, from, to,1); list.setadapter(adapter); list.setonitemclicklistener(new adapterview.onitemclicklistener() {  @override public void onitemclick(adapterview<?> parent, final view view, int position, long id)  { view.setselected(true); } 

it's working fine ,when select item in listview selected , problem when scroll listview item selected doesn't remain highlighted.

as others have mentioned, due list view recycling views, selected view recycled when scroll off page, root cause of problem.

you need set choice mode on listview choice_mode_single using either xml attribute choicemode or setchoicemode() method. has been awhile, think automatically makes clicked on position selected item, if not, can call setselection(position) on listview (which parent parameter) in onitemclick


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -