如何突出所选的项目的ListView? [英] How to highlight selected item in ListView?

查看:81
本文介绍了如何突出所选的项目的ListView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道Android不突出TouchMode的东西。但是我做类似于在其中选择从右侧活动的左侧,显示细节的东西Gmail应用程序的东西(不知道谷歌是如何做到这一点)。

I know that android doesn't highlight anything in TouchMode. But I am doing something similar to the gmail application in which you select stuff from the left side and show details on the right side of the activity(wonder how Google did that).

这样的故事就是我要强调什么在左侧ListView中被选中。我发现了一些类似的问题和解决方案基本上是:

So the story is I have to highlight what's been selected on the left side ListView. I've found some similar questions and the solutions are basically:

1.override适配器的getView方法的setBackground选定位置

1.override the adapter's getView method and setBackground for selected position

视图onItemClick的2.setBackground,并明确其花药选择

2.setBackground of the view onItemClick and clear it for anther selection

但没有人因怪异的行为为我工作。当我点击一个项目,突出它的第五个项目后,它突出强调了,等等等等,我向下滚动列表

But none of them worked for me due to a weird behaviour: As I click on one item and highlight it, the fifth item after it is highlighted as well, and so on so forth as I scroll down the list.

有什么建议? THX!

Any suggestions? THX!

推荐答案

使用listView.setChoiceMode(INT choiceMode);

Use listView.setChoiceMode(int choiceMode);

参数

choiceMode一个CHOICE_MODE_NONE,CHOICE_MODE_SINGLE,或CHOICE_MODE_MULTIPLE从类android.widget.AbsListView

choiceMode One of CHOICE_MODE_NONE, CHOICE_MODE_SINGLE, or CHOICE_MODE_MULTIPLE from class android.widget.AbsListView

http://developer.android.com/reference/android/widget/AbsListView.html#setChoiceMode(int)

您还需要添加MultiChoiceModeListener,你可以有CHOICE_MODE_SINGLE

You also need to add MultiChoiceModeListener, you can have CHOICE_MODE_SINGLE

<一个href="http://developer.android.com/reference/android/widget/AbsListView.html#setMultiChoiceModeListener%28android.widget.AbsListView.MultiChoiceModeListener%29"相对=nofollow>(android.widget.AbsListView.MultiChoiceModeListener)

请参考下面示例

<一个href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List16.html" rel="nofollow">http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List16.html

这篇关于如何突出所选的项目的ListView?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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