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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:54:48+00:00 2026-06-03T02:54:48+00:00

I want to populate a list from my database. I have the following code:

  • 0

I want to populate a list from my database.

I have the following code:

setContentView(R.layout.pro);
    addProFromDB();

}

How I should populate the multi xCodexInlinexPlacexHolderx?

private void addProFromDB() {
    // TODO Auto-generated method stub

    ArrayList<String> results = new ArrayList<String>();
    SQLiteDatabase sampleDB = null;

    try {
        list = (ListView)findViewById(android.R.id.list);
        list.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        sampleDB = this.openOrCreateDatabase(SAMPLE_DB_NAME, 1, null);
        sampleDB.execSQL("create table tbl_product("
                + "pro_id integer PRIMARY KEY autoincrement,"
                + "pro_name text," + "pro_price integer);");

        sampleDB.execSQL("insert into tbl_product(pro_name, pro_price) values ('oil', '200' );");

        Cursor c = sampleDB.query(SAMPLE_TABLE_NAMES, null, null, null, null, null,
                null);
        char pro_nameColumnIndex = (char) c.getColumnIndexOrThrow("pro_name");
        int pro_priceColumnIndex = (int) c.getColumnIndexOrThrow("pro_price");

    } finally {
        if (sampleDB != null)
        sampleDB.close();
    }
    setListAdapter(new ArrayAdapter<String>(this,
        android.R.layout.simple_list_item_checked, new ArrayList()));

It is not giving any error, but not showing the inserted items either.

  • 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-03T02:54:49+00:00Added an answer on June 3, 2026 at 2:54 am

    Number of issues are there in your code snippet.

    1. You are creating table tbl_product every time you run you app.
    2. You are inserting new element in your newly created table every time.
    3. and finally you are passing empty array to your ArrayAdapter as
      new ArrayList()

    I would recommend you to go through any tutorial, and sort out things step by step.

    I’m suggesting you to follow this tutorial, and use CursorAdapter when you are working with sqlite.

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

Sidebar

Related Questions

I populate web form with dynamic list of exams from database. I want user
I have made the following code to retrive data from SQLite database. public Cursor
I have a table layout that I want to populate with the result from
Basically, I have populated a dropdown list using php from a database on a
I have two databases: Transactions and Customer List I want to populate the customer
Afternoon All, I have a dropdown list which extracts data from my SQL database
I have some code that grabs some rows from a table and I want
I am using a AutoCompleteTextView in my code and loading the list from database
I am trying to populate a dropdown list from database. In my view file
I have a list view which is populated from a SQL database. I am

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.