Listview is not updating, Android

Asked

Viewed 93 times

0

Guys, I have the code below. I created a FloatingActionButton who takes pictures of all the items that are on ListView, but the method list.getChildAt(i). isEnable is returning nullpointer. Some idea to solve?

ListView list = JTaritronClientReportFragment.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);
}

1 answer

1

You can use the following method:

    list.invalidateViews(); // Para atualizar a lista

And to update the content if the invalidateViews() does not work and you have an Adapter:

    seuAdapter.notifyDataSetChanged(); // Para atualizar o cursor da lista

If these alternatives don’t work visit this post, as it’s similar to your question:

https://stackoverflow.com/questions/2250770/how-to-refresh-android-listview

I hope I’ve helped.

Thank you

  • i took another look at the code and is updating only if (list.getChildAt(i).isEnabled()) is returning nullpointer, I will change the question

  • It is returning null, probably because in its list in the getChildAt element( i ) it may be empty.

  • i think q is returning null pq is not appearing on the screen, for example I have a listview with 6 items, it takes picture of the first three twice, then updates the screen

Browser other questions tagged

You are not signed in. Login or sign up in order to post.