Skip to content Skip to sidebar Skip to footer

Pass Checkbox Data To Next Activity

I am creating a list of items with a listview with checkbox. I want to pass the checked options to next activity. For this I am using an string array for passing the results to o

Solution 1:

I will suggest you to use a arraylist to add items selected and pass the arraylist to the second activity

   checked = new ArrayList<String>();
   publicvoidonClick(View view) {
        SparseBooleanArray positions = mListView.getCheckedItemPositions();
        for(int index = 0; index < array.length; index++) {
            if(positions.get(index)==true)
            {
                 checked.add(array[index]);
            }
        }
        Intent i1 = new Intent(MainActivity.this, TailoredthreeActivity.class);
            i1.putStringArrayListExtra("list",checked);
        startActivity(i1);
    }

To receive

 ArrayList<String> getChecked;   
 Bundleextras= getIntent().getExtras();
    if(extras!=null)
    {
      getChecked = extras.getStringArrayList("list");

   }

Solution 2:

You need to initialize the array first because every array is an object in java

publicvoid onClick(View view) {
        SparseBooleanArray positions = mListView.getCheckedItemPositions();
         builder= newString[array.length];
        for(int index = 0; index < array.length; index++) {
            if(positions.get(index)==true)
            {
                 builder[index] = array[index];
            }
        }

Post a Comment for "Pass Checkbox Data To Next Activity"