0

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.

3 Answers3

0

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.

Faruk Yazici
  • 2,344
  • 18
  • 38
0

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.

Community
  • 1
  • 1
Sean C.
  • 228
  • 2
  • 8
0

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));
}
ENN
  • 58
  • 1
  • 6