Working fine when we use selector. but this is temporary. if focus change of list item then selected color also change. But i want different. When we click on list view item then that particular item color change. After that we can move another items of list view. When we click another item. then again this particular selected item want to set color, and last colored list item release from color
Related
I've created a list view which shows some data. When the user clicks on a specific item, its color should change.
This works, except that every 10th item changes color, not just the item clicked.
try add in your activity
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
this shloud make your selction single not multiaple selction
Any one please suggest, How to change icon image of selected item icon in Expanded Listview? In my senario if once click selected item ,previous icon change to normal state and selected item icon change to selected state.
In ExpandableBaseAdapter's getGroupView, there will be argument called isSelected strong text
So by using that argument, change your view or background based on your need.
if(isSelected){
image.setBitmap(R.drawable.my_drawable_selected);
}else{
image.setBitmap(R.drawable.my_drawable_normal);
}
Scenario.
Say list view has 5 items. When I click on a particular item, that particular item gets highlighted. When i click on another item, the previous item is unselected and the new item is highlighted.
I am able to do so by holding 2 views. CurrentSelectedItemView and PreviousSelectedItemView. Using these two views I am changing the text color and backgrounds of these two rows. But how do i change the color and background of other rows. I do not want to reset the adapter every time a row is selected.
Say text color is black and background is white. When a row is selected,the colors reverse. For other rows,I need to change the text color to grey. I able to do fr 2 rows only... current and previous.
Is there any simple way of doing this?
You should keep track of last selected index to change the background of previous selected item.
To make changes in listview you need to alteast called adapter.notifydatachanged()
I have Implemented Side Menu Navigation. The left side menu is a listview and onclick of item opens an Activity. I want to change the text color of an item when the user clicks on it and remain this color of item until he clicks on another item. And after click on another item change the color of first item to the default color and change the other item color and so on. Any help or code example will be highly appreciated. Thanks in advance.
Use CheckedTextView for text of list item and set android:textColor value to a color state list resource.
Remember to set list view: android:choiceMode="singleChoice" as well
I have a listview with a textview as each item. I want to change the textcolor of the selected item. For this use the onItemSelected method to make the changes. Say first I select the 1st row, the first row's textcolor changes. Now when I select the 2nd row, its text color also changes, but I want the 1st row's color to change back to its default color. How do I do that, since in the onItemSelected I only get the refernce of the currently selected item and not the last selected. Is there any way other than holding a reference to the last selected view.
When first item is selected store its position in instance variable of your activity, lets name it currentlySelected. Then combine with this Android: Access child views from a ListView
in order to get the view at position currentlySelected and change it's textcolor.
Instead of doing it in Java, you can let android handles it in the xml file. See Color State List Resource.