Ale*_*lex 6 java sqlite user-interface android list
我正在使用Google的新片段(Android 3)实现splitview.
当用户从列表中选择某些内容时,它会在详细信息区域中显示值并保持列表项突出显示.
当我使用数组适配器时,它会在添加以下内容后保持列表项集中:
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
getListView().setItemChecked(postition, true);
但是当我使用SimpleCursorAdapter和自定义行xml文件更改为使用数据库时,它会在我按下时突出显示.
"我想在列表视图中保持突出显示项目"
您需要为列表行设置激活的样式.问题在于,这仅适用于API级别11及更高版本.
一种方法是使用两种不同的样式.在res/values-v11/styles.xml,你可以有:
<?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>
而res/values/styles.xml你会:
<?xml version="1.0" encoding="utf-8"?>
<resources>
  <style name="activated">
  </style>
</resources>
然后,您的行布局将使用该activated样式,例如:
<?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"
/>
结合您现有的CHOICE_MODE_SINGLE逻辑,这将使您的行在点击后激活.