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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:59:59+00:00 2026-06-05T12:59:59+00:00

I want to populate a listview from 2 tables in SQLite database. The listview

  • 0

I want to populate a listview from 2 tables in SQLite database. The listview will consist of 3views: an imageview and 2 textviews.

  • 1st table: imageview and textview1
  • 2nd table: textview2

I can successfully query data from one table and display it in a listview, but have no idea how to query from the 2nd one, then add it to the list.

The codes below displays a listview with data only from my_folders.
How can I change it such that textview1 shows data from table my_folders and textview2 shows data from my_expenses. Can anyone please help?

This is mymain:

public class mymain extends ListActivity {
ListView listContent;

SimpleCursorAdapter cursorAdapter;
final DBAdapter mySQLiteAdapter = new DBAdapter(this);
Cursor cursor;

/** Called when the activity is first created. */

@Override
public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

// setContentView(R.layout.list_example);

  listContent = (ListView) findViewById(R.id.custom_list);
  final DBAdapter mySQLiteAdapter = new DBAdapter(this);

  mySQLiteAdapter.open();

  cursor = mySQLiteAdapter.getAllFolders();

  String[] from = new String[] { DBAdapter.KEY_NAME,DBAdapter.KEY_CURRENCY };
  int[] to = new int[] { R.id.name_row, R.id.notes_row };


  cursorAdapter = new SimpleCursorAdapter(this, R.layout.list_row, cursor,
          from, to);

  setListAdapter(cursorAdapter);
  mySQLiteAdapter.close();

}
}

This my database:

import android.database.Cursor;

public class DBAdapter {
    public static final String KEY_ROWID = "_id"; 
    public static final String KEY_NAME = "name";
    public static final String KEY_CURRENCY = "currency";
    public static final String KEY_NOTES = "notes";
    public static final String KEY_EXPENSE_NAME = "expense_name";
    public static final String KEY_EXPENSE_AMOUNT = "expense_amount";
    public static final String KEY_EXPENSE_DATE = "expense_date";
    public static final String KEY_EXPENSE_TIME = "expense_time";
    public static final String KEY_EXPENSE_NOTES = "expense_notes";
    public static final String KEY_EFOLDERID = "e_fid";

    private static final String TAG = "DBAdapter";

    private static final String DATABASE_NAME = "MyDB";
    private static final String DATABASE_TABLE1 = "my_folders";
    private static final String DATABASE_TABLE2 = "my_expenses";
    private static final int DATABASE_VERSION = 1;

    private static final String DATABASE_CREATE_FOLDERS = 
        "create table my_folders (_id integer primary key autoincrement, "
            + "name text not null, currency text not null, notes text);";

    private static final String DATABASE_CREATE_EXPENSES = 
        "create table my_expenses (_id integer primary key autoincrement, "
            + "expense_name text not null, expense_amount real not null, " +
                    "expense_date text not null, expense_time text not null," +
                    "expense_notes text,"
        + "e_fid integer not null," +
                    "FOREIGN KEY ("+ KEY_EFOLDERID+ ") REFERENCES " + DATABASE_TABLE1 +" ("+ >KEY_ROWID + ") ON DELETE CASCADE);";

    // ---retrieves all the contacts---
    public Cursor getAllFolders() {
        return db.query(DATABASE_TABLE1, new String[] { KEY_ROWID, KEY_NAME,
                KEY_CURRENCY, KEY_NOTES}, null, null, null, null, null);
    }

    // ---retrieves all the expenses---
    public Cursor getAllExpenses() {
        return db.query(DATABASE_TABLE2, new String[] { KEY_ROWID, KEY_EXPENSE_NAME,
                KEY_EXPENSE_AMOUNT, KEY_EXPENSE_DATE, KEY_EXPENSE_TIME, KEY_EXPENSE_NOTES, >KEY_EFOLDERID}, null, null, 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-05T13:00:00+00:00Added an answer on June 5, 2026 at 1:00 pm

    The best way to get the data from the 2 tables is to use a join query, something like

    SELECT name, expense_name, expense_notes
    FROM my_folders, my_expenses
    WHERE my_folders._id = my_folders.e_fid
    

    This will return all the data in 1 Cursor and which you can then put in your view

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

Sidebar

Related Questions

I want to populate a table form a MYSQL database. I have defined the
I have a listview which populates its content from SQLite Database. Here's my code:
I want to populate a list from my database. I have the following code:
I have an xml data file and I want to populate a listview in
I want to populate my database with test data my user and profile models
I want to populate a table, defined in layout xml file through the programmatic
I want to populate a drop down menu with a column from a MySQL
I want to populate database with Cyrillic text namespace :db do task :populate =>
I'm trying to populate images from a directory into a listview with a small
I have a ListActivity with a ListView populated onStart with data from a database.

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.