【发布时间】:2013-04-07 05:43:34
【问题描述】:
我创建了一个从 ListActivity 类派生的类 RecordActivity,并为 .xml 中定义的 ListView 设置选择模式和选择器。默认行为是仅当我按下所选项目时才会突出显示。我想保持选定的项目突出显示。我试图覆盖 ArrayAdapter 的 getView 方法,但是它不起作用。任何帮助将不胜感激。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
public class RecordsActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.records);
List<Record> values = getAllRecords();
// Use the SimpleCursorAdapter to show the
// elements in a ListView
adapter = new ArrayAdapter<Record>(this, android.R.layout.simple_list_item_1,
values);
setListAdapter(adapter);
getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
getListView().setSelector(android.R.color.holo_red_dark);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
selectedItem = position;
v.setSelected(true);
}
}
【问题讨论】:
-
您可以在这些链接中找到自己的方式:[Link1][1] [Link2][2] [Link3][3] [Link4][4] [1]: stackoverflow.com/questions/5058291/… [2 ]:stackoverflow.com/questions/10788688/… [3]:stackoverflow.com/questions/5853719/… [4]:stackoverflow.com/questions/5972155/…
标签: android highlight listactivity