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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:42:29+00:00 2026-06-14T02:42:29+00:00

I have a listview populated by a database. The listview displays some columns of

  • 0

I have a listview populated by a database. The listview displays some columns of the database. I want to be able to click the listItem and display a new activity that shows that whole record. I am trying to do this by passing the id between through an intent but it is not working. The activity is starting but the textViews aren’t being populated. I have included the relevent code snippets here. Would really appreciate some help

MainActivity

public class MainActivity extends ListActivity {
    ....
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ...
        ...  
    }

    private void fillList() {
        ListView lv = getListView();

        Cursor c = db.getData();
        startManagingCursor(c);

        CustomCursorAdapter adapter = new CustomCursorAdapter(getApplicationContext(), c);
        lv.setAdapter(adapter);

        lv.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view, int position, long id){
                Intent k = new Intent(MainActivity.this, ProductDetails.class);
                k.putExtra("item_id", id);
                startActivity(k);
            }
        });
    }

}

ProdDetails

public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        db = new ProdDB(this);
        setContentView(R.layout.product_details);
        db.open();

        long id = getIntent().getLongExtra("item_id", 0);

        Cursor cursor = db.getDetails(id);
        while(cursor.moveToFirst()){
            tv1.setText(cursor.getString(cursor.getColumnIndex(ProdDB.KEY_PRODCODE)));
            tv2.setText(cursor.getString(cursor.getColumnIndex(ProdDB.KEY_PRODNAME)));
            ...
            ...
        }
    }
}

DB.getDetails() – from ProdDB

String[] columns = new String[] {KEY_ROWID, 
        KEY_PRODCODE,
        KEY_PRODNAME,
        KEY_PRODTYPE,
        KEY_PRODCAT,
        KEY_PRODPRICE,
        KEY_PRODRRP,
        KEY_PRODSUPPLIER,
        KEY_NOTES};
return db.query(DB_TABLE, columns, KEY_ROWID + " = ?", new String[]{String.valueOf(id)}, null, null, null);
  • 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-14T02:42:31+00:00Added an answer on June 14, 2026 at 2:42 am

    you’re having issue cause you’re using while(cursor.moveToFirst()){. if you must use the while loop then you should use the .moveToNext() instead. Otherwise, you can just take out the while loop for moveToFirst since i’m assuming you only need the one row. as for why, don’t ask me, i couldn’t tell you.

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

Sidebar

Related Questions

I have a ListView in my activity that is populated from a database Cursor
I have a ListView in a ListFragment that is populated via a database query.
I have a ListView that is populated using an XML file. However, I want
I have a listview that is being populated by information from a database using
I have listview having customized some textview and one imageview. When I long click
I have an activity that extends ListView. I populate my list with the results
I have a listview which is populated by a SimpleCursorAdapter that is binding data
I have a ListView with custom adapter which is populated from local sqlite database.
I have once again problems concerning a ListView which is populated by a database.
I have an activity with a listview that is displaying the results of a

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.