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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T17:13:22+00:00 2026-06-08T17:13:22+00:00

My app lets user select a category and then input other info based on

  • 0

My app lets user select a category and then input other info based on the category. Say they pick category ‘Electronics’ then they can input CD, PS3, iPod etc in it. I have several categories like Hobbies, General, Home etc.

I would like to display the items in a listview sorted by category like this:

Electronics
 -CD
 -PS3
 -iPod
Books
 -Perl
 -Android is fun
 -C

etc etc…

I am fetching all the data from the db using:

return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID,KEY_CATEGORY
                KEY_NAME, KEY_STATUS, KEY_DESCRIPTION}, null, null, null, null, null);

i also tried using the rawQuery and using the DISTINCT tag but that’s not going to work, since it will pick unique items. I am using a simpleCursorAdapter to display the data:

SimpleCursorAdapter list =
    new SimpleCursorAdapter(this, R.layout.items, c, mapFrom, mapTo);
setListAdapter(list);
  • 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-08T17:13:25+00:00Added an answer on June 8, 2026 at 5:13 pm

    I guessing that you want this:

    return mDb.query(DATABASE_TABLE, 
                new String[] {KEY_ROWID, KEY_CATEGORY, KEY_NAME, KEY_STATUS, KEY_DESCRIPTION}, 
                null, null, null, null, 
                KEY_CATEGORY + ", " + KEY_NAME);
    

    Using the Order By parameter your query is first ordered by category then name. This would give you a result like:

    Category, Name
    --------------
    Books, Android is fun
    Books, C
    Books, Perl
    Electronics, CD
    Electronics, iPod
    Electronics, PS3
    

    If you only wanted to list Books, then you simply use:

    return mDb.query(DATABASE_TABLE, 
                new String[] {KEY_ROWID, KEY_CATEGORY, KEY_NAME, KEY_STATUS, KEY_DESCRIPTION}, 
                KEY_CATEGORY + "=?", 
                new String[] {"Books"}, 
                null, null, 
                KEY_NAME);
    

    Of course, if you only want to display the category and name in a ListView then you it will be more efficient to shorten you SELECT clause to only what you need: new String[] {KEY_ROWID, KEY_CATEGORY, KEY_NAME}.

    Addition from comments

    In order to get a result like this:

    Books
        Android is fun
        C
        Perl
    Electronics
        CD
        iPod
        PS3
    

    You can either use an ExpandableListView or process the Cursor yourself into a List<String> and pass this to a ArrayAdapter.

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

Sidebar

Related Questions

I have a C# Silverlight app that lets the user select which spreadsheet they
I'm building an app that lets a user select a folder, the app then
I have a web app which lets the user select the excel spreadsheet and
I have an app that lets the user interact with several forms. I can
I have an app that contains several activities...so lets say user is navigating activity
Lets say you have a web app related Android app that requires the user
lets say i have app id, app secret id and user uid now i
I am learning Swing and wrote an app that lets user select an image
I'm currently working on an app that lets the user choose an MP3 audio
I'm writing a simple iPhone app which lets a user access a series of

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.