Eduardo Bonfa
Eduardo Bonfa

Reputation: 288

ListView.setSelection is not working properly

I have the code below. I created a FloatActionButton to take pictures of all items in the ListView, but I need the screen to update to take them all. The list.setSelection is working, but is working after the while ends.

For example: I have a ListView that contains 6 images, the code bellow is taking pictures of the first three twice, and then update the screen to the last 3.

{

    ListView list = JMainFragment.getInstance().getList();

    list.setSelection(0);
    int j = 0;
    while (j < list.getCount()) {
        int lastPosition = list.getLastVisiblePosition();
        for (int i = 0; i < list.getLastVisiblePosition() - list.getFirstVisiblePosition(); i++) {
            if (list.getChildAt(i).isEnabled()) {
                JUtil.saveScreenShot(list.getChildAt(i), "operadora" + j + ".png");
                j++;
            }
        }
        list.setSelection(lastPosition);
        list.
    }  

Upvotes: 1

Views: 1196

Answers (1)

Andrea Dusza
Andrea Dusza

Reputation: 2110

How about list.invalidateViews(); after list.setSelection(lastPosition);?

Upvotes: 1

Related Questions