Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
357 views
in Technique[技术] by (71.8m points)

android - How to highlight selected item in ListView?

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).

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 the adapter's getView method and setBackground for selected position

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.

Any suggestions? THX!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use listView.setChoiceMode(int choiceMode);

Parameters

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)

You also need to add MultiChoiceModeListener, you can have CHOICE_MODE_SINGLE

(android.widget.AbsListView.MultiChoiceModeListener)

Refer to the sample below

http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/view/List16.html


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...