0

for Android Studio with Java

Listview have not correctly scrollview, so mean I select first item in Listview but Selecting first item both another a item. So mean, showing me two item, one's my selected item another random a item

What can I do about this situation

enter image description hereenter image description hereenter image description here

for Listview, selected item not correctly work

Abdullah
  • 77
  • 1
  • 1
  • 6

2 Answers2

0
Map<Integer, String> Green = new HashMap<>();

Map<Integer, String> white = new HashMap<>();


checkBox_TumParca.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

if(checkBox_TumParca.isChecked()){

for(int i=0;i<barkodlar.size();i++){

listemiz.getChildAt(i).setBackgroundColor(Color.GREEN);

Green.put(i,"Yeşil");

white.remove(i);

}

}else{

for(int i=0;i<barkodlar.size();i++){

listemiz.getChildAt(i).setBackgroundColor(Color.WHITE);

white.put(i,"Beyaz");

Green.remove(i);

}

}

}

});





ArrayList<Integer> posit = new ArrayList<>();

ArrayList<Integer> yesil = new ArrayList<>();

ArrayList<Integer> beyaz = new ArrayList<>();




listemiz.setOnItemClickListener(new AdapterView.OnItemClickListener() {



@Override


public void onItemClick(AdapterView<?> parent, View view, int position,


long id) {





try {

String a=Green.get(position);

if (a!="Yeşil"){

listemiz.getChildAt(position).setBackgroundColor(Color.GREEN);

Green.put(position,"Yeşil");

white.remove(position);

}

else if (a=="Yeşil"){

listemiz.getChildAt(position).setBackgroundColor(Color.WHITE);

white.put(position,"Beyaz");

Green.remove(position);

}

}catch (Exception ex){

dialog("",ex.getMessage(),false);

}




}


});
jcredking
  • 314
  • 1
  • 10
Abdullah
  • 77
  • 1
  • 1
  • 6
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 21 '23 at 16:11
0

Automatically selected item element in list view please refer this 2 link, I hope you getting your solution

This is first link

This is second link