[Solved] How do you select multiple items from a listview and work upon them on android [closed]


I think you have problem in selecting multiple list items or either on knowing which list item of activity is selected or which one is unselected .

all of these things can be easily done by creating a getter setter class with two custom field one is string selected and one is unselected with all other getter setter objects.

then create a custom arraylist with getter setter data type like this one

ArrayList<MyGetterSetter> listData = new ArrayList<MyGetterSetter> ();

and getter setter class:

Class MyGetterSetter
{
   int selected , unselected ;

    public int getSelected() {
        return selected;
    }
    public void setSelected(int selected) {
        this.selected = selected;
    }

    public int getUnselected() {
        return unselected;
    }
    public void setUnselected(int unselected) {
        this.unselected = unselected;
    }
}

then set by default value of selected =0; and unselected =1;
at the time you add real time data to your getter setters usually during json parsing or fetching data from database and inserting that to arraylist.

then set your list adapter with the custom array list you created to display views data.

MyGetterSetter model = listData.get(position);

if(model.getSelected==1)
{
 yourCheckbox.setSelected(true);
}
else
{
yourCheckbox.setSelected(false);
}

//Also set the checkbox/button click listener in adapter by this way..

yourCheckbox.setonClickListener(new View.onClickListener
{
public void onClick(View view)
{
if(model.getSelected==1)
{
 yourCheckbox.setSelected(false);
 model.setSelected=0;
 model.setUnSelected=1;
}
else
{
yourCheckbox.setSelected(true);
model.setSelected=1;
model.setUnSelected=0;
}
}

then on each item click by activity list item click listener change the values of selected =1 if selected or unselected = 0 ;
if list item is selected by user
either set selected=0 and unselected = 1;
if unselected by user.

then right below the list attach a button on that button click loop whole the adapter data and or array-list data and check the status and position.
if found selected=1
then calculate the amount for that particular item with other selected list items.

solved How do you select multiple items from a listview and work upon them on android [closed]