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 8975239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:49:36+00:00 2026-06-15T18:49:36+00:00

Currently the list when populated is starting with the view @ the bottom of

  • 0

Currently the list when populated is starting with the view @ the bottom of the list. Is there a way using listAdapters to force it to the top of the list?

Currently the orientation scrolls to the bottom on create. Is there a way to pin the screen to the top when it creates? https://i.stack.imgur.com/TR9S4.jpg in this example you see that entry 1 on create is shoved upwards to make room for six… Instead I want it to populate like this. https://i.stack.imgur.com/Pu7n3.jpg… entry 1 is the top of the list and 6 is pushed off to the bottom for the scroll.

If you look at the picture above you will notice it starts at the bottom of the list instead of at the top. Any Ideas?

mAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mStrings);
        setListAdapter(mAdapter);
        registerForContextMenu(getListView());


populateFields();

private void populateFields() {
       if (mRowId != null) {
           Cursor note = mDbHelper.fetchDaily(mRowId);
           startManagingCursor(note);
           String body = note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_DBODY));
           mAdapter.clear();
           if (!(body.trim().equals(""))){
               String bodysplit[] = body.split(",");
               for (int i = 0; i < bodysplit.length; i++) {
               mAdapter.add(bodysplit[i].trim());
               } 
           }
       }
   }

**edited to fix != string error.

  • 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-15T18:49:36+00:00Added an answer on June 15, 2026 at 6:49 pm

    You are completely changing the adapter, so the scroll position is lost in the process… You can use:

    ListView listView = getListView();
    int position = listView.getFirstVisiblePosition();
    if (!(body.trim().equals(""))){
       String bodysplit[] = body.split(",");
       for (int i = 0; i < bodysplit.length; i++) {
          mAdapter.add(bodysplit[i].trim());
       } 
    }
    
    listView.setSelection(position);
    

    But this is not perfect as it is, if a row is added before position the index will be off. If your list contains unique values you can use ArrayAdapter#getPosition(), to find the new index.


    While I still recommend using a CursorAdapter, because it handles large table data better, I want to address a point on efficiency with your ArrayAdapter code.

    By using adapter.clear() and adapter.add() you are asking the ListView to redraw itself on every step… potentially dozens or hundreds of times. Instead you should work with the ArrayList directly and then ask the ListView to redraw once itself with ArrayAdapter#notifyDataSetChanged() after the loop completes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way to get the list of currently running threads in objective-C?
I am currently ordering a list of custom objects using the IQueryable OrderBy method
I have a dropdown list that is currently populated from a result set of
I currently have a dropdown list being populated with values from a database. I
I have a list view which is populated from a SQL database. I am
I'm currently in the process of creating a shared Edit/Create view for my game
Currently the list item # appears on the right. If you remove the float
I currently have a list of DateTimes stored as the timezone's UTC datetime. When
I currently have a list of things to update in the given mysqli query:
All I need is to get the list of currently open documents in the

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.