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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:37:39+00:00 2026-05-23T03:37:39+00:00

I have in my DBAdapter, a getAll which should pull all the data from

  • 0

I have in my DBAdapter, a getAll which should pull all the data from the database:

public Cursor getAllFinalscores()
{
    return db.query(DATABASE_TABLE, new String[] {
            KEY_ROWID,
            KEY_DATE,
            KEY_FINALSCORE,
            KEY_HOLESPLAYED},
            null, null, null, null, null);
}

and right now, I have it so that when a user wants to view all the data (from the main activity) it pulls it all as follows:

public void DisplayFinalscore(Cursor c)
{
    Toast.makeText(this,
            "DATE: " + c.getString(1) + "\n" +
            "FINALSCORE: " + c.getString(2) + "\n" +
            "HOLESPLAYED: " + c.getString(3),
            Toast.LENGTH_LONG).show();
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
        case R.id.past_games:
            DBAdapter db = new DBAdapter(this);

            db.open();
            Cursor c = db.getAllFinalscores();
            if (c.moveToFirst())
            {
                do {
                    DisplayFinalscore(c);
                }
                while (c.moveToNext());
            }
            db.close();

        }
    return true;
}

This works, however, it displays them all as little messages that pop up. I am looking to display them in a list on a separate screen.

I created a new class (PastGames) which looks like the following:

public class PastGames extends ListActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.pastgames);

        DBAdapter db = new DBAdapter(this);

        db.open();
        Cursor c = db.getAllFinalscores();
        startManagingCursor(c);

        String[] from = new String[] { DBAdapter.KEY_DATE};
        int[] to = new int[] {R.id.text1};

        SimpleCursorAdapter games = new SimpleCursorAdapter(this, layout.pastgames_row, c, from, to);
        setListAdapter(games);
        db.close();
    }
}

I also have my xml files:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ListView android:id="@id/android:list"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>
<TextView android:id="@id/android:empty"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/no_games"/>

and the row layout

<TextView android:id="@+id/text1"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>

Could help me with what I need to do in order to get that info into those layouts?

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-05-23T03:37:40+00:00Added an answer on May 23, 2026 at 3:37 am

    Okay, a few things:

    First, to access the Database, you should use a SQLiteOpenHelper. It helps you read/write to it and create/update the Database.

    Also, the startManagingCursor()-method is deprecated and shouldn’t be used anymore. If you need to close your cursor, do it manually.

    Don’t open your Database-connection in the onCreate-method as it’s only called when the Activity is first created. Use the onStart-method instead. Also, don’t use the onCreate-method to populate the List. Create a new method for this and call it in the onStart-method, too. If the Activity gets backgrounded and foregrounded again, there won’t be a problem with older data.

    Also, if you have a ListActivity, you don’t need a Layout containing a ListView. This is done automatically.

    That’s all I see for the moment. If you’re getting any errors or exceptions, please post those messages, too. See if this gets you any further.

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

Sidebar

Related Questions

I have created a database for my android app which contains static data and
I have a list that i fill with data from a database, and now
I have written the following code for inserting video bytes into the database DBAdapter.java
I have written a service To delete data from a table when data inputed
I have a List of Items which I retrieved from my Sqlite DB... I
I have a class: public class DbAdapter { private DbHelper dbHelper; private SQLiteDatabase db;
I have an app in android that in a different thread from the UI(which
I have the following code which does nothing but reading some values from a
I have an autocomplete which does a query to DB....when doing a click on
I have the following code: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.screen_database); db=new DBAdapter(this);

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.