Android Expanded ListView Selected Item icon change - android

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);
}

Related

Custom AlertDialog with a List

I want to create this exactly AlertDialog, but I didn't know how to do it, How to change the typeface for the selected item and How to add this icon on the right for the selected item too
You can make dialog like this and set Id for it whenever you clicking any text that clickable text's Id is store in that Id's variable and do another thing set icon with boolean.
like,
if your position is matched with Id then icon will visible else it will invisible

How to keep a listview item selected after clicking on it

I have an android app which uses a ListView. When I click on any item, there is a light gray color which appears and fades out. How can I make this gray color to remain on the selected item instead of disappearing? Please take a look at the gif which shows the scenario which I want to avoid.
Current Scenario
First of all you need to change background color on clicked.
take reference from here
And then add this line inside your listview's OnItemClickListener
listView.setSelection(int position);
You can set item Selected according to your need using this method
listView.setSelection(0);
listView.getSelectedView().setSelected(true);
OR
listView.setItemChecked(0, true)

Android: change text color of an item in listview

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

How to set background colour for listview selected item

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

android change view of selected item in adapterview

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.

Categories

Resources