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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:09:33+00:00 2026-06-03T13:09:33+00:00

What is the best way to implement a ListFragment using SQLite database. Currently I

  • 0

What is the best way to implement a ListFragment using SQLite database. Currently I have created an DBAdapter to facilitate opening, closing, and fetching records into a SimpleCursorAdapter. I have my MainActivity which implements an ActionBar with Navigation Tabs which I would like to display a different ListView for each tab.

Here is my ListFragment:

public class MaterialsListFragment extends ListFragment {

public DBAdapter db;   

@Override
public View onCreateView(LayoutInflater inflater, 
ViewGroup container, Bundle savedInstanceState) { 


    return inflater.inflate(R.layout.portrait_material_view, container, false);
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // create new DBAdapter
    db = new DBAdapter(getActivity());
    db.open();

    Cursor c = db.getAllRecords();

    String[] from = new String[] { DBAdapter.KEY_IDNO, DBAdapter.KEY_MATERIAL };
    int[] to = new int[] { R.id.idno, R.id.materials };        

    // Now create an array adapter and set it to display using our row
    MyListAdapter materials = new MyListAdapter(this, R.layout.list_cell, c, from, to);
    setListAdapter(materials);
 }

Here is MyListAdapter code which for now is in it’s own class file:

public class MyListAdapter extends SimpleCursorAdapter {

    public MyListAdapter(Context context, int layout, Cursor cursor, String[] from, int[] to) {
        super(context, layout , cursor, from, to);
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {

        // Create the idno textview with background image
        TextView idno = (TextView) view.findViewById(R.id.idno);
        idno.setText(cursor.getSring(3));

        // create the material textview
        TextView materials = (TextView) view.findViewById(R.id.materials);
        materials.setText(cursor.getString(1));
    }
}

Is this the way to go about this? I would appreciate any suggestion you may have or if you know of any good examples.

  • 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-03T13:09:36+00:00Added an answer on June 3, 2026 at 1:09 pm

    I was able to get this to work, so I think I’m on the right track. I had to make this modification to get it to run, but it seems to be working well.

          MyListAdapter materials = new MyListAdapter(getActivity(), R.layout.list_cell, c, from, to);
    

    I would still be interested in any suggestions or ways to improve this approach.

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

Sidebar

Related Questions

What's the best way to implement FTP upload and download in PHP? I'm using
What's the best way implement MS SQL full-text search using all the normal things
What is the best way to implement web services in PHP? I have heard
I'm struggling to find the best way to implement my update to the database
what is the best way to implement C++ functionality in Java? Currently I call
What's the best way to implement a stack using linked lists in Java? EDIT:
What is the best way to implement an Ajax request queue using jQuery? Specifically,
What's the best way to implement runtime filtering of Core Data objects using NSFetchedResultsController?
What is the best way to implement security using active directory roles on an
What is the best way to implement Gather-Scatter like operation using WCF and C#

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.