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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:04:37+00:00 2026-06-01T18:04:37+00:00

I have successfully created a database table in android ( SQLite ). I am

  • 0

I have successfully created a database table in android ( SQLite ). I am trying to sort elements in the database according to the first or last name ( ascending /descending ) . ( i have buttons in the context menu for this purpose ) . I am having issues writing the SQL statement . Any idea?

public void onCreate(Bundle savedInstanceState) 
    {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.database);

        ListView lv=(ListView)findViewById(R.id.mylist);


         dbh = new DatabaseHelper(this);
         c = dbh.getReadableDatabase().rawQuery("SELECT _id, " + 
             DatabaseHelper.NAME + 
  ", " + DatabaseHelper.LASTNAME + 
      ", " + DatabaseHelper.ans2 + 
                        " FROM " +
                DatabaseHelper.TABLE_NAME, null); // initializing 


            String[] dataFrom ={DatabaseHelper.NAME, DatabaseHelper.LASTNAME, DatabaseHelper.ans2};
            int[] dataTo = {R.id.name, R.id.value1, R.id.value2};               
            SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
                    R.layout.row, c, dataFrom, dataTo);

           lv.setAdapter(adapter);

           registerForContextMenu(lv);


    }
  • 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-01T18:04:38+00:00Added an answer on June 1, 2026 at 6:04 pm

    I think you are mixing up things. You can’t control how it is stored in database. All you need to worry would be how you want to get data from database. You need to use order by clause (By default it is Asc on column you specified).

     c = dbh.getReadableDatabase().rawQuery("SELECT _id, " + 
                 DatabaseHelper.NAME + 
      ", " + DatabaseHelper.LASTNAME + 
          ", " + DatabaseHelper.ans2 + 
                            " FROM " +
                    DatabaseHelper.TABLE_NAME ORDER BY yourColumnName, null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have successfully created a table using SQlite in android. There is a column
I have a table created with PHP from an Sql Database that successfully displays
I have successfully created a database and performed my first migration using: class CreateUsers
I have created an sqlite table using the following statement: CREATE TABLE IF NOT
i have created table using Sqlite3.and also inserted record in that table.its running successfully.but
I have a database wherein per day a table is created to log process
Database tables are created successfully by <property name=hibernate.hbm2ddl.auto value=create/> in persistence.xml, however each time
I have created a table with three entries name,adress and phone no. Now i
I have File-Stream enabled database. I have created table with column that has the
I have successfully created an app that reads from a bundled .plist file and

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.