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

  • Home
  • SEARCH
  • 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 3319280
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:48:22+00:00 2026-05-17T22:48:22+00:00

I have written a small android app that grabs some data and displays it

  • 0

I have written a small android app that grabs some data and displays it in a ListView.

I want to have the list sorted in ascending order (no prob). But when I add a new item it stays at the bottom of the list even when the view/app is reloaded. It seems the only data that is being sorted is the entries that were created in the database OnCreate() method.

I’m not sure what code to provide but i’ll start by showing you snippets of the DBAdapter class, then from the main app class.

Database construction query:

    private static final String DATABASE_CREATE =
    "create table "+ DATABASE_TABLE
    + "("
    + FIELD_ROWID+" integer primary key autoincrement, "
    + FIELD_NAME +" varchar(30) not null, " + FIELD_TELEPHONE + " varchar(20) not null, " 
    + FIELD_ADDRESS + " text not null,"
    + FIELD_URL + " varchar(255) not null);";

Function to get list of data:

    public Cursor getRestaurants() 
{
 Cursor result = null;
 try{
  result = db.query(DATABASE_TABLE, new String[] {FIELD_ROWID, FIELD_NAME}, null, null, null, null, FIELD_NAME+" ASC");
 }
 catch (Exception e)
 {
  Log.v("applog", e.getMessage());
 }
 return result;
}

Here is a snippet of the main method. Here you can see that I am calling the getRestaurants() function shown above. I’m stumped as to why the data isn’t being sorted.

Any advice greatly appreciated. Thanks in advance.

public class Assignment2 extends ListActivity {

 // Set up some global variables. 
 private static final int ADD_NEW_ID = Menu.FIRST;
 private static final int CLOSE_APP_ID = ADD_NEW_ID+1;
 private final DBAdapter db = new DBAdapter(this);
 private static CursorAdapter curAdapter = null;
 private static Cursor rawData = null;
 @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        db.open(); // Open connection to restaurant db.

     rawData = db.getRestaurants();
     Log.v("applog", rawData.getCount()+" Restaurants loaded from DB.");

     if(rawData.getCount() == 0)
     {
      Toast.makeText(getApplicationContext(), "No restaurants found.", Toast.LENGTH_SHORT).show();
     }
     try
     {
      /* The following two arrays are used to map DB fields to ListView items
       * From a custom layout file.
       */
      // Array of db fields to be used when converting cursor to ListView
            String[] strFields = { "name", BaseColumns._ID };
            // Array of listview id's to be used when populating the ListView
            int[] intFields = { R.id.first };

            curAdapter = new SimpleCursorAdapter(this, R.layout.row, rawData, strFields, intFields);
     }
     catch (Exception e)
     { 
      Log.v("applog", e.getMessage()); 
     }  

     // Apply the converter cursor to the current ListView
     setListAdapter(curAdapter);
        db.close(); // Close connection to restaurant db.
  • 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-05-17T22:48:22+00:00Added an answer on May 17, 2026 at 10:48 pm

    Im not sure exactly what your problem is but, it all looks good minus these lines of code I have when I get a callback from my new data insert

            if(cursor!=null)cursor.requery();
            adapter.notifyDataSetChanged();
    

    Hopefully this will fix your issue.

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

Sidebar

Related Questions

No related questions found

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.