I am stuck with this issue, i need to change the color of textview's background on item click in listview and hold that color till i clicked on other item.
Thanks Kind regards.
I am stuck with this issue, i need to change the color of textview's background on item click in listview and hold that color till i clicked on other item.
Thanks Kind regards.
You should do this in your getView() method. And each time you click on an item, you should set the adapter again and reload the list. This is all I can tell you without seeing your codes.
Hey this looks similar to this issue: Android ListView selected item stay highlighted
You need to use a drawable to control the background color based off the state.
You can try my idea: create integer variable that will save your position in onItemClick
public class Activity implements onItemClickListener{
private int prevPosition;
.....
list.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
prevPosition = position;
//call your adapter here then use notifyDataSetChanged();
}
});
CustomAdapter{
......
getView(int position, View convertView, ViewGroup parent){
//setCondition
if(prevPosition == position){
//do something here for your selected item list
textView.setBackground( getResources().getDrawable(R.drawable.selectedBackground));
}
else{
///do something here for unselected list item
layout.setBackground( getResources().getDrawable(R.drawable.unselectedBackground));
}