0

The String array count is three.I am checking the gallery images three from gridview.

Based on array count,it is checked three images.But after Closing the application and come back it always show exceed debug.It have to again check three checkbox.

MainActivity.java:

String[] strArr = {"One","Two","Three"};
    
int size = strArr.length;

    public void changeSelection(View v, int position) {

        if (data.get(position).isSeleted) {
            data.get(position).isSeleted = false;
            
            Log.e("UnChecked","Unchecked");
            
        } else if(size < strArr.length){
            data.get(position).isSeleted = true;
            
            Log.e("Checked","Checked");
            
        } else {
            Log.e("Exceed", "Exceed");
        }

        ((ViewHolder) v.getTag()).imgQueueMultiSelected.setSelected(data.get(position).isSeleted);
    }

Can anyone help me with this? Thank you.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
UserAgr
  • 1
  • 1
  • 5

1 Answers1

0

According to your code. You might actually have a typo:

if (data.get(position).isSelected) {
        data.get(position).isSelected = false;

        Log.e("UnChecked","Unchecked");

    } else if(size < strArr.length){
        data.get(position).isSelected = true;

        Log.e("Checked","Checked");

    }

isSeleted should be isSelected

Also, size will never be lesser than strArr.length since they both are the same things. This results your if else statement always going to the final else statement.

Your checkbox being unchecked is because you did not save the states of your application. Maybe this answer will help you out: How to save the state of an Android CheckBox when the users exits the application?

Community
  • 1
  • 1
shouxian
  • 1
  • 1