Store item with high list with SimpleCursorAdapter

I am implementing splitview using a new snippet from Google (Android 3).

when the user selects something from the list, he shows the value in the details pane and emphasizes the preservation of the list item .

when I used an array adapter, it holds the list item focused after adding the following:

getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE); getListView().setItemChecked(postition, true); 

but when I change the database usage with SimpleCursorAdapter and a custom XML string file, it only gets highlighted when I click.

"I want to save the selected item as a list"

+6
source share
1 answer

You need to set the activated style for the list line. The trick is that this is only available at API level 11 and above.

One way to do this is to use two separate styles. In res/values-v11/styles.xml you can:

 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="activated" parent="android:Theme.Holo"> <item name="android:background">?android:attr/activatedBackgroundIndicator</item> </style> </resources> 

While res/values/styles.xml you will have:

 <?xml version="1.0" encoding="utf-8"?> <resources> <style name="activated"> </style> </resources> 

Then your line layout will use the activated style, for example:

 <?xml version="1.0" encoding="utf-8"?> <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:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical" android:layout_marginLeft="4dip" android:minHeight="?android:attr/listPreferredItemHeight" style="@style/activated" /> 

Combined with the existing CHOICE_MODE_SINGLE logic CHOICE_MODE_SINGLE this will cause your line to be activated after using it.

+9
source

Source: https://habr.com/ru/post/899375/


All Articles