简体   繁体   中英

Comparing arraylist with string element android

I am using a listview with an effientadapter.

In my effiicient adapter I initialized and arraylist

public static ArrayList<String> stringPosition = new ArrayList<String>();

and populate it using where position in arraylist is 1 and 2.

stringPosition.add(position);

Then in my listview activity in onintemclicklister I check if values stored match the position. but when I click of more than one stored value in arraylist. I get only the last item in the arraylist. how can I

Comparing string with values from arraylist and check if match.

for (int i=0;i<EfficientAdapter.stringPosition.size();i++){

        String x = EfficientAdapter.stringPosition.get(i).toString();
        System.out.println("x: " +x);

        if (x.equals(String.valueOf(position)))
            DetailWork.GREEN_OR_BLUE=1;

        else
            DetailWork.GREEN_OR_BLUE=0;

    }

how can I solved this issue and is it the best way to compare if some element of listrows is identical to list position. ?

I can't edit my comment anymore...

for CHOICE_MODE_MULTIPLE use
SparseBooleanArray sba = listView.getCheckedItemPositions();

for CHOICE_MODE_SINGLE use int pos = listView.getSelectedItemPosition();

You can later fetch all these positions from your adapter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM