I\'ve prepared a custom listview using BaseAdapter. Now I want to change color of selected item of listview on click event. And multiple items should be selected. Here I am
"Thanks a lot for your help. I've done all this. Now I found that when I click one item in list, another item is also get selected automatically. Is there any problem with BaseAdapter?"
For this problem you need to save states of your listview rows that whether that row is selected or not in getview check if it is selected then set color of row as selected. You need to save state also whenever you select or deselect any row. Here is a similar example instead of checkbox, row will be there in your case... Hope it will help you i am giving you a link ....
How to implement a button that gets all checkbox's state and adds the value of checked item into arraylist?
Since you've implemented BaseAdapter, which has a core method called getView, you can easily store the states of items in BaseAdapter. For example, you can use List to store the states.
Then, a listener of the ListView should be implemented, as described in http://developer.android.com/reference/android/widget/AdapterView.html#setOnClickListener(android.view.View.OnClickListener). The documentation of OnItemClickListener is here, http://developer.android.com/reference/android/widget/AdapterView.OnItemClickListener.html, through which you can get the positions of the clicks.
Finally, change the state of the items after on-click events, and call notifyDataSetChanged() in adapter to notify that the data has been changed and you'll see the updated selected items.
Its very simple... Just try the following code...
In your List Adapter:
Define an Integer Array first
ArrayList<Integer> itemPos = new ArrayList<Integer>();
then use this code in your getView Method :
if (itemPos.contains(position)) {
holder.txtOne.setTextColor(Color.BLUE);
} else {
holder.txtOne.setTextColor(Color.WHITE);
}
Now use this code in click event of your Text View :
if (!itemPos.contains(position)) {
holder.txtOne.setTextColor(Color.BLUE);
itemPos.add(position);
notifyDataSetChanged();
} else {
holder.txtOne.setTextColor(Color.WHITE);
notifyDataSetChanged();
int po = itemPos.indexOf(position);
itemPos.remove(po);
}