Android:在ListView打开时将项目设置为选中状态? [英] Android:To set an item as selected when the ListView opens?

查看:34
本文介绍了Android:在ListView打开时将项目设置为选中状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个 Activity 有一个 Button 和一个 ListView.最初,只有 Button 可见.按下按钮时,将显示 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 position) 就是你所需要的.但是,取决于设备是否处于触摸模式,它可能有也可能没有视觉效果(背景突出显示).更多详情请参考Android ListView选择问题

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 Android ListView Selection Problem

这篇关于Android:在ListView打开时将项目设置为选中状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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