手动选择时,Android Listview项会突出显示,但以编程方式选择时则不会突出显示

时间:2015-01-10 23:29:24

标签: android listview highlighting

当手动选择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);

}
}

0 个答案:

没有答案