Highlight ListView selected row
-
I have a list of albums (several hundred). When I touch the selected album I want to offer the user a choice of playing the whole album, or moving to its track ListView. No problem. However, after touching the ablum in albumListView I want the row to remain highlighted so the user knows which item they have clicked on, and can then move to OK or PLAY. How do I highlight a row in ListView?
-
Answer:
Quoted from http://developer.android.com/resources/articles/touch-mode.html Imagine a simple application, ApiDemos for example, that shows a list of text items. The user can freely navigate through the list using the trackball but also, alternatively, scroll and fling the list using the touch screen. The issue in this scenario is how to handle the selection properly when the user manipulates the list through the touch screen. In this case, if the user selects an item at the top of the list and then flings the list towards the bottom, what should happen to the selection? Should it remain on the item and scroll off the screen? What should happen if the user then decided to move the selection with the trackball? Or worse, what should happen if the user presses the trackball to act upon the currently selected item, which is not shown on screen anymore? After careful consideration, we decided to remove the selection altogether, when the user manipulates the UI through the touch screen. In touch mode, there is no focus and no selection. Any selected item in a list of in a grid becomes unselected as soon as the user enters touch mode. Similarly, any focused widgets become unfocused when the user enters touch mode. The image below illustrates what happens when the user touches a list after selecting an item with the trackball.
Dirk Bruere at Stack Overflow Visit the source
Other answers
Maaalte is correct, in touch mode lists do not show the focus highlight on a current item since there is no current item in touch mode. Stateful selection like you're describing that persists while you interact with other parts of the UI is another matter though. You can use CHOICE_MODE_SINGLE to express a stateful selection in a list. It will treat selection as a checked state. As long as the view that your adapter returns implements the Checkable interface, you can display the selected state however you choose. (Setting a background on the item view or otherwise. It does not actually need to show a check box widget.) You can then use the item checked methods of ListView to manipulate or determine the selection.
adamp
Implement your list with single choice mode: android:choiceMode=singleChoice Just as the default android.R.layout.simple_list_item_single_choice uses a RadioButton to denote the selected choice, you can implement a custom highlight state or similar in your list item layout to respond to the choice changes. Methods like getCheckedItemPosition() can be used by your application to determine which item the user currently has chosen, if necessary. Hope that Helps!
Devunwired
You can also use the SelectableListView that I wrote: http://udinic.wordpress.com/2011/07/01/selectablelistview-make-selection-work/
Udinic
Related Q & A:
- How to highlight the current chapter of the Youtube chapter marker player?Best solution by Stack Overflow
- How to get the column value when a row is selected in wpf listview?Best solution by Stack Overflow
- How to execute a selected statement?Best solution by Stack Overflow
- How to get rid of highlight on link?Best solution by Yahoo! Answers
- How and why are the wonders of the world selected?Best solution by quora.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.