I have a ListView
. I updated its adapter, and call notifydatasetchanged()
. I want to wait until the list finishes drawing and then call getLastVisiblePosition() on the list to check the last item.
Calling getLastVisiblePosition()
right after notifydatasetchanged()
doesn't work because the list hasnt finished drawing yet.
The best way that I found to know when has finished laying down the items was using the LinearLayoutManager. For example: private RecyclerView recyclerView; ... recyclerView = findViewById(R.
For ArrayAdapter for instance, there is the notifyDataSetChanged() method which should be called after you've updated the array list which holds all your data, in order to refresh the ListView .
Pull to Refresh is used to update the data within the list in our android application. For implementing this we have to use Swipe to Refresh Layout. Using this widget when the user swipes down the list which is being displayed on the screen is updated.
Hopefully this can help:
addOnLayoutChangeListener
on the listview.notifyDataSetChanged()
;OnLayoutChangeListener
when completedPerform code on update (getLastVisiblePosition()
in your case)
mListView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
@Override
public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
mListView.removeOnLayoutChangeListener(this);
Log.e(TAG, "updated");
}
});
mAdapter.notifyDataSetChanged();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With