在ListView控件编程设置启动项 [英] Set activated item in ListView programmatically

查看:117
本文介绍了在ListView控件编程设置启动项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的的ListView 与已 setChoiceMode 设置为 ListView的某些项目。 CHOICE_MODE_SINGLE ,这意味着,当我接触一个项目,它被突出显示。通过这种方式,用户可以看到哪些菜单选项(在的ListView 是一个菜单)被选择:

I have a simple ListView with some items that have setChoiceMode set to ListView.CHOICE_MODE_SINGLE, which means when I touch an item, it is highlighted. This way the user can see what menu choice (the ListView is a menu) was chosen:

listView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

不过,我想改变从code表示选择(请勿触摸)。我想这样的:

However, I want to change that selection from code (not by touching). I tried this:

listView.setSelection(0);

但似乎没有任何效果。大概是因为选择和激活是不同的概念。没有 setActivated(INT)方法可用。

推荐答案

您可以选择具有以下code项:

you can select item with following code:

listView.setItemChecked(position, true);

这篇关于在ListView控件编程设置启动项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆