skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER
    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);
    
    }
    
    
    
    
    }
    
    
    });
    

  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search