i am implementing a splitview using the new fragment from Google (Android 3).
when user choose something from the list it is show value in the details area and keep list item highlight.
when i used array adapter it is keep list item focused after adding the following:
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
getListView().setItemChecked(postition, true);
but when i change to use database using SimpleCursorAdapter and custom row xml file it is highlight just when i press.
"i want to keep highlight item in list view"
You need to set the activated style for your list row. The catch is that this is only available on API Level 11 and higher.
One way to do this is to use two separate styles. In res/values-v11/styles.xml
, you could have:
<?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>
Whereas res/values/styles.xml
you would have:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="activated">
</style>
</resources>
Your row layout would then use that activated
style, such as:
<?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 your existing CHOICE_MODE_SINGLE
logic, this will leave your row activated after it is tapped.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With