Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9034321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T08:26:40+00:00 2026-06-16T08:26:40+00:00

Peculiar problem I’m having with a cursoradapter in a listfragment. In my onLoadFinished I

  • 0

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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T08:26:41+00:00Added an answer on June 16, 2026 at 8:26 am

    Rewrite:

    If I take them out of the runnable it works with calling setselection just once. However then I don’t get a delayed scrolling effect (to show the user it scrolled), which I guess I sorta like.

    When I took a closer look at your code I noticed that you were calling getView() in the Adapter manually. Adapters recycle their views in a very particular but unpredictable order and attempting to call getView() yourself might create unwanted behavior… You should avoid doing this, try a different tactic:

    @Override
    public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
        mAdapter.swapCursor(data); // or changeCursor(data) as explained below
        getListView().postDelayed(new Runnable() {
            @Override
            public void run() {
                ListView listView = getListView(); // Save a local reference rather than calling `getListView()` three times
                listView.setSelection(selectedposition);
                listView.performItemClick(listView.getChildAt(0), selectedposition, selectedposition);
            }
        }, 500);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having a peculiar problem with the order in which TextBox controls are
I am having a peculiar problem with the order in which FlowLayoutPanels are added
I am having a peculiar problem with getting an integer from an ajax response.
I'm having the most peculiar problem, and I was hoping I someone could point
I'm having a peculiar problem in a WPF-app I've written. It has a single
I'm having quite a peculiar problem with PhoneGap and JQuery Mobile, using the latest
I am having a peculiar problem. Every time,I call merge, on the session, Hibernate
I have a peculiar problem, which I think that a lot of other people
I am facing a peculiar problem. The problem is, my webapp is being installed
I have a peculiar problem. I created a normal Objective C class called SampleTable.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.