安卓:到ListView打开时为选择设置项目?项目、ListView

2023-09-06 08:52:47 作者:别用你吻过别人的嘴说爱我

这是活动有一个按钮和一个ListView。 最初,只有按钮是可见的。当按钮pssed $ P $,则显示的ListView。 在显示时,有可能是我的选择显示一个特定的项目/集中?

An activity has a Button and a ListView. Initially, only the Button is visible. When the button is pressed, the ListView is displayed. When displayed, is it possible for me to show one particular item as selected/focussed?

一个用例可能是假设它是语言设置的列表,并将列表打开时,当前选择的语言必须显示为高亮显示。

A use case could be that suppose it is a list of language settings and when the list opens, the currently selected language must be shown as highlighted.

如果我知道这个项目的索引,如何将它设置为集中展示?

If I know the index of the item, how to set it as focused on display?

推荐答案

总之,ListView控件:: setSelection(INT位置)是你所需要的。然而,根据设备是否处于触摸模式或不是,它可以或可以不具有视觉效果(背景高亮)。欲了解更多详情,请参阅http://stackoverflow.com/questions/2042278/android-listview-selection-problem

In short, ListView::setSelection(int position) is what you need. However, depending on whether the device is in touch mode or not, it may or may not have visual effect (background highlighting). For more details, refer to http://stackoverflow.com/questions/2042278/android-listview-selection-problem