Therefore, apparently, I was fired from the wrong path, because I had to look for the selected "checked" items, and not the "selected" items. So many answers told me to use selector with my ListView layout using android:listSelector="@drawable/myselector , but I really needed to use selector with my row layout. The solution is actually pretty simple, I'll post it below:
range hood /rowbackgroundselector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_activated="true" android:drawable="@android:color/holo_green_light"/> </selector>
- note how you use "state_activated" to detect if the item is "checked" ...
range hood /mylistrow.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="center_vertical" android:background="@drawable/rowbackgroundselector" android:padding="10sp" />
- using selector for string background
MainActivity.onListItemClick ()
public void onListItemClick(ListView l, View v, int position, long id) { getListView().setItemChecked(pos, true); }
Finally, make sure your adapter uses your own string layout
mAdapter = new ArrayAdapter<FileTag>(this.getActivity(), R.layout.mylistrow, mList);
woojoo666
source share