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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:06:10+00:00 2026-06-07T10:06:10+00:00

I have read so many posts about how to populate the listview from a

  • 0

I have read so many posts about how to populate the listview from a database. but i simply cant do it on my app! i dont know what im doing wrong. I´m very new to programming so there are allot of things i dont understand but im trying to learn 🙂

I add items to the database without any problems using this code in the activity:

String selectedstone = (String) stonespinner.getSelectedItem();
String weight = etaddweight.getText().toString();

db.addStone(new MyStonesDatabase(selectedstone, weight));

in the DatabaseHandler.java i have this:

// Adding new stone
void addStone(MyStonesDatabase stone) {
    SQLiteDatabase db = this.getWritableDatabase();

    ContentValues values = new ContentValues();
    values.put(KEY_STONE, stone.getStone());
    values.put(KEY_WEIGHT, stone.getWeight());

    // Inserting Row
    db.insert(TABLE_MYSTONES, null, values);
    db.close(); // Closing database connection
}

I can see that my database gets populated by running this:

Log.d("Reading: ", "Reading all items..");
List<MyStonesDatabase> items = db.getAllstones();

for (MyStonesDatabase cn : items) {
String log = "Id: " + cn.getID() + ", Stone: "
+ cn.getStone() + ", Weight: " + cn.getWeight();
// Writing Items to log
Log.d("Name: ", log);
}

But when trying to have a listview to show the database my app either crashes or dont show anything. In my DatabaseHandler.java i have this:

// Getting All items from database
public List<MyStonesDatabase> getAllstones() {
    List<MyStonesDatabase> stoneList = new ArrayList<MyStonesDatabase>();
    // Select All Query
    String selectQuery = "SELECT  * FROM " + TABLE_MYSTONES;

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

    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
        do {
            MyStonesDatabase stone = new MyStonesDatabase();
            stone.setID(Integer.parseInt(cursor.getString(0)));
            stone.setStone(cursor.getString(1));
            stone.setWeight(cursor.getString(2));

            // Adding stone to list
            stoneList.add(stone);
        } while (cursor.moveToNext());
    }

    // return stonelist
    return stone;
}

I dont know what to put in my activity that should show the listview.

public class MyStones extends ListActivity {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);


}

}

Can someone please help me, im about to give up hehe 🙂
thanks!

  • 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-07T10:06:11+00:00Added an answer on June 7, 2026 at 10:06 am

    Here is a great article/tutorial that might help you. Populating your listView isn’t as simple as just doing something in your Activity. You need to create a listAdapter and a couple other things. In the tutorial, they use hard-coded values, in an array. You might try getting that to work, then removing the hard-coded data, and using the data you are getting from your DB.

    Getting this to work is a little trickier than you might think, but not overly complicated.

    Hope this helps:

    http://www.ezzylearning.com/tutorial.aspx?tid=1763429

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

Sidebar

Related Questions

I have read many posts and blogs about rewriting and I know there is
I have read many posts about this now but I do not still understand
I have read through many posts and articles about styling a Wordpress Gallery, but
I have read many questions about Android, J2ME and RecordStore , but I still
I have read many questions about the facebook login but until not I didnt
I have read many posts about setting up unit testing in Zend Framework and
Ok, I have read a lot of posts and resources about this but I
Alright...I've given the site a fair search and have read over many posts about
I have read many posts on Session-scoped data in MVC, but I am still
I have read many posts about how to specify the foreign key name in

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.