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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:38:24+00:00 2026-05-21T19:38:24+00:00

In my database I have 2 tables. For a table I want to display

  • 0

In my database I have 2 tables. For a table I want to display only the items which has a certain id in the second column. I have an adapter for all the items from the table but I don’t know how should it look like for viewing only the items I need. Any idea is welcome.

Here is my adapter :

private void populate(){
        c=prod.fetchAll();
        startManagingCursor(c);

        adapter=new SimpleCursorAdapter(this,R.layout.listproduct,c,
                new String[] {ProductDbAdapter.KEY_ITEM,ProductDbAdapter.KEY_QUANTITY,ProductDbAdapter.KEY_UNITS},
                new int[] {R.id.prod1,R.id.prod2,R.id.prod3});

       lv.setAdapter(adapter);

    }

The code for ProductDbAdapter is :

public class ProductDbAdapter extends AbstractDbAdapter {

    public static final String KEY_LISTID = "list_id";
    public static final String KEY_ITEM = "item";
    public static final String KEY_QUANTITY="quantity";
    public static final String KEY_UNITS="units";

    public static final String KEY_ROWID = "_id";

    private static final String DATABASE_TABLE = "products";


    public ProductDbAdapter(Context ctx) {
        super(ctx);
    }


    public long create(Integer listid, String item,String quantity,String units) {
        ContentValues args = new ContentValues();
        args.put(KEY_LISTID,listid);
        args.put(KEY_ITEM,item);
        args.put(KEY_QUANTITY,quantity);
        args.put(KEY_UNITS,units);

        return mDb.insert(DATABASE_TABLE, null,args);
    }


    public boolean updateproduct(long rowId,Integer listid, String item,String quantity,String units) {
        ContentValues values = new ContentValues();
        values.put(KEY_LISTID, listid);
        values.put(KEY_ITEM, item);
        values.put(KEY_QUANTITY, quantity);
        values.put(KEY_UNITS,units);
        return mDb.update(DATABASE_TABLE, values, KEY_ROWID + "="+ rowId, null) > 0;
    }

    public boolean delete(long rowId) {
        return mDb.delete(DATABASE_TABLE, KEY_ROWID + "=" + rowId, null) > 0;
    }


    public Cursor fetchAll() {
        return mDb.query(DATABASE_TABLE, new String[] {KEY_ROWID, KEY_LISTID,KEY_ITEM,KEY_QUANTITY,
                KEY_UNITS}, null, null, null, null, null);
    }


    public Cursor fetch(long rowId) throws SQLException {
        Cursor mCursor =
            mDb.query(true, DATABASE_TABLE, new String[] {KEY_ROWID,
                    KEY_LISTID,KEY_ITEM,KEY_QUANTITY, KEY_UNITS}, KEY_ROWID + "=" + rowId, null,
                    null, null, null, null);
        if (mCursor != null) {
            mCursor.moveToFirst();
        }
        return mCursor;

    }
}

What I am trying to do is to display only the items with a certain list_id..

  • 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-21T19:38:25+00:00Added an answer on May 21, 2026 at 7:38 pm

    Why do you request a cursor which returns all item when you only want items with a certain id? Change your database query so you only get the items with the ids you define in the where-statement of your database query.

    Let the database so the job of filtering the correct items for you, it’s not the job of an adapter.

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

Sidebar

Related Questions

I have a Database table that I want to display in a DataGridView. However,
I have a DataTable which I want to save to a SQLite Database Table.
I have a database framework where I have two tables. The first table has
I have one table in my Database that has column names: buildNumber , result
I have a sample database like below, and I want to display only the
We have a database with a tables called 'Sites' This table has the columns,
I have a database with three tables: user_table country_table city_table I want to write
I have a database table that i want to allow my friends to update.
We have a database where every table name starts with WW. I want to
i have a stack of messages in database table. i want to send these

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.