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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:40:04+00:00 2026-06-17T20:40:04+00:00

I am trying to insert data from SQLite to a listview. I have tried

  • 0

I am trying to insert data from SQLite to a listview. I have tried look for example codes but they do not work. The database part is from AndroidHive’s SQL tutorial. In his post the code to get all data in DB is(i edited the data fields) :

// Getting All carts item
public List<Cart> getAllCart() {
    List<Cart> cartList = new ArrayList<Cart>();
    // Select All Query
    String selectQuery = "SELECT  * FROM " + TABLE;

    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
        do {
            Cart cart = new Cart();
            cart.setID(Integer.parseInt(cursor.getString(0)));
            cart.setPID(Integer.parseInt(cursor.getString(1)));
            cart.setName(cursor.getString(2));
            cart.setPrice(Double.parseDouble(cursor.getString(3)));
            cart.setQut(Integer.parseInt(cursor.getString(4)));
            // Adding cart to list
            cartList.add(cart);
        } while (cursor.moveToNext());
    }

    // return cart list
    return cartList;
}

how do put this “getAllCart()” to my listview. Thanks alot!!

  • 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-17T20:40:05+00:00Added an answer on June 17, 2026 at 8:40 pm

    to get data from SQLite you can try like this:

          public List<String[]> selectAll()
    {
    
        List<String[]> list = new ArrayList<String[]>();
        Cursor cursor = db.query(TABLE_NAME, new String[] { "id","name","number","skypeId","address" },
                null, null, null, null, "name asc"); 
    
        int x=0;
        if (cursor.moveToFirst()) {
            do {
                String[] b1=new String[]{cursor.getString(0),cursor.getString(1),cursor.getString(2),cursor.getString(3),cursor.getString(4)};
    
                list.add(b1);
    
                x=x+1;
            } while (cursor.moveToNext());
        }
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        } 
        cursor.close();
    
        return list;
    }
    

    and to show it in a list view :

        List<String[]> list = new ArrayList<String[]>();
    List<String[]> names2 =null ;
         names2 = dm.selectAll();
    
        stg1=new String[names2.size()]; 
    
        int x=0;
        String stg;
    
        for (String[] name : names2) {
            stg = name[1]+" - "+name[2]+ " - "+name[3]+" - "+name[4];
    
            stg1[x]=stg;
            x++;
        }
    
    
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(   
                this,android.R.layout.simple_list_item_1,   
                stg1);
        this.setListAdapter(adapter);
    }      
    

    refer this tutorial you will get an idea: http://www.vogella.com/articles/AndroidSQLite/article.html

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

Sidebar

Related Questions

I am trying to insert data from table a to table b (both are
I am trying to insert data from a database into a textarea. I can't
I am trying to insert data from one table that was imported from an
Language: OO PHP 5+ DB: MySQL I am trying to insert data from a
So I am trying to use jQuery to insert data from an ajax call.
I am trying to insert data about an item's price from an HTML form
I'm trying to run .ajax and insert a data element from the onClick of
I am trying to select data from two tables and insert it into another
The data I am trying to insert is from a database, and while inserting
I am trying to insert a data into SQLite database using Python. INSERT INTO

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.