0

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. ?

6
  • This is the first time I'm hearing of a EfficientAdapter. What does it do? Commented Jul 11, 2013 at 10:39
  • 2
    listView.getSelectedItemPositions() Commented Jul 11, 2013 at 10:40
  • I have to correct my previous comment, getSelectedPositions does not exist. I have ammended in answer. Commented Jul 11, 2013 at 10:49
  • 1
    what is the ArrayList of your items that you have passed to your Adapter ?? if they are String ,so you can use : x.equals(items.get(position)) Commented Jul 11, 2013 at 11:15
  • 1
    I suggest you post your EfficientAdapter as it contains nonstandard methods, unless you really believe that it's got nothing to do with the solution and/or isn't proprietary, unsharable code. Commented Jul 11, 2013 at 11:16

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.