Peculiar problem I'm having with a cursoradapter in a listfragment.
In my onLoadFinished I select the previously selected item in order to scroll the listview to the previous position (and then highlight that item).
This works splendidly, except for the scrolling part.
If I just use one post and delay it (even say 5 seconds), the item gets selected but the list will not scroll (the selected item may out of view at this time) With or without delay same behavior with just one post.
I have to post setSelection AGAIN to get the listview to scroll so the selected item is in view.
It doesn't matter how long I delay the initial or second scroll post.
Here's my grubby workaround, but I'm not pleased with it. Any ideas?
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
mAdapter.swapCursor(data);
getListView().post(new Runnable() {
@Override
public void run() {
getListView().requestFocusFromTouch();
getListView().setSelection(selectedposition);
getListView().performItemClick(getListView().getAdapter().getView(selectedposition, null, null), selectedposition, selectedid);
getListView().clearFocus();
}
});
getListView().postDelayed(new Runnable() {
@Override
public void run() {
getListView().requestFocusFromTouch();
getListView().setSelection(selectedposition);
getListView().performItemClick(getListView().getAdapter().getView(selectedposition, null, null), selectedposition, selectedid);
getListView().clearFocus();
}
}, 500);
}