I create a class RecordActivity derived from ListActivity class, and set the choice mode and selector for the ListView defined in the .xml. The default behavior is the selected item will be highlighted only when I pressed it. I want to keep the selected item to be highlighted. I tried to override the getView method for ArrayAdapter, however, it doesn't work. Any help will be appreciated.
<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);
}
}