当手动选择myListView项时,它会突出显示,但是当以编程方式(通过myListView.performItemClick(myListView.getAdapter().getView(17, null, null), 17, 17);
)进行选择时,如果我添加此2调用,则项目不会突出显示事件:
l.setSelection(position);
l.setItemChecked(position, true);
请让我知道如何突出显示以编程方式选择的列表视图项目。
感谢。
public class PlaylistActivity extends ListActivity {
private static ListView myListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_search);
easyTracker = EasyTracker.getInstance(PlaylistActivity.this);
ActionBar actionBar = getActionBar();
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
if (!MainActivity.playlistItem.isEmpty())
MainActivity.playlistItem.clear();
for (Story aStory : MainActivity.stories) {
if (aStory.get_text() != null && ((aStory.get_text()).toLowerCase(Locale.getDefault()).
contains("5"))){
MainActivity.playlistItem.add(aStory);
}
}
setListAdapter(new MyStoryAdaptater(PlaylistActivity.this,R.layout.activity_mainview, MainActivity.playlistItem));
myListView = getListView();
myListView.setSelector(android.R.color.darker_gray);
myListView.performItemClick(myListView.getAdapter().getView(17, null, null), 17, 17);
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
l.setSelection(position);
l.setItemChecked(position, true);
}
}