Skip to content Skip to sidebar Skip to footer

How To Compare Two Arraylist And Enable Toggle Accordingly In Android

I have an app in which listview with two arraylist suppose 1st 'listStorage' and second is 'existingDataSet' i have to compare these two arraylist value if found same then enable t

Solution 1:

 for (int i = 0 ; i < existingDataSet.size() ; i++){
        if (existingDataSet.get(i).getPackName().equalsIgnoreCase(listStorage.get(i).getPackName())){
            listViewHolder.switchCompat.setChecked(true);
        }
    }
}

Solution 2:

can you try this? switch should retain its value false if not contains within 2 list when on getView because it trigger several times.

boolean isChecked = false
for (int i = 0; i<existingDataSet.size(); i++){
        for (int j= 0; j<listStorage.size(); j++){
            if (existingDataSet.get(i).getPackName().equalsIgnoreCase(listStorage.get(j).getPackName())){
               isChecked = true;
            }
        }
    }

 listViewHolder.switchCompat.setChecked(isChecked);

Post a Comment for "How To Compare Two Arraylist And Enable Toggle Accordingly In Android"