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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:49:09+00:00 2026-06-16T11:49:09+00:00

Basically I have code that initialises the database in a DatabaseHelper extended class (see

  • 0

Basically I have code that initialises the database in a DatabaseHelper extended class (see below) and I’m currently getting only one of the results to display?

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE IF NOT EXISTS host ("
            + BaseColumns._ID
            + " INTEGER PRIMARY KEY AUTOINCREMENT, name VARCHAR, mac_address VARCHAR)");

    ContentValues host_values = new ContentValues();
    host_values.put("name", "test host");
    host_values.put("mac_address", "ffffffffffff");

    db.insert("host", null, host_values);

    ContentValues host_values2 = new ContentValues();
    host_values.put("name", "test me host");
    host_values.put("mac_address", "eeeeeeeeeeee");

    db.insert("host", null, host_values2);

}

This is the code, I’m using a ListFragment over a ListActivity is that makes any difference?

public class TargetListFragment extends ListFragment {

private SQLiteDatabase database;

private CursorAdapter dataSource;

private static final String fields[] = { "name", "mac_address", 
    BaseColumns._ID };

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
            setHasOptionsMenu(true);
    DatabaseHelper helper = new DatabaseHelper(this.getActivity().getApplicationContext());
    database = helper.getWritableDatabase();
    Cursor data = database.query("host", fields, 
        null, null, null, null, null);

    dataSource = new SimpleCursorAdapter(this.getActivity().getApplicationContext(), 
        R.layout.target_row, data, fields,  
        new int[] { R.id.target_name, R.id.mac_address });

    setListAdapter(dataSource);
}

This is really bothering me as it seems almost like the cursor is only dealing with the first row and then being closed but I can’t think of anything that would cause that?

Again in case it’s useful here’s the XML of the row view.

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="wrap_content" android:id="@+id/target_row_layout"
            android:orientation="vertical" android:layout_width="wrap_content">

            <TextView android:layout_width="fill_parent"
                    android:layout_height="wrap_content" android:id="@+id/target_name"
                    style="@style/target_list.item_name" /> <!--style="@style/target_list.item_name"-->
            <TextView android:layout_width="fill_parent"
                    android:layout_height="wrap_content" android:id="@+id/mac_address"
                    style="@style/target_list.mac_address" /> <!--style="@style/target_list.mac_address"-->
    </LinearLayout>
  • 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-16T11:49:10+00:00Added an answer on June 16, 2026 at 11:49 am

    You are using host_values where you meant to use host_values2… insert() won’t add a second row because all of the values inside host_values2 are null:

    ContentValues host_values2 = new ContentValues();
    host_values2.put("name", "test me host");  // Change variable
    host_values2.put("mac_address", "eeeeeeeeeeee");  // Change variable
    
    db.insert("host", null, host_values2);
    

    (Alternatively you can simply remove host_values2 and write over the previous data host_values.)

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

Sidebar

Related Questions

I have this horribly stripped delphi code that basically login to server, save cookie
I have this small piece of code that basically takes a list and runs
I have several Code Analysis CA1704:IdentifiersShouldBeSpelledCorrectly warnings that I want to suppress. Basically, they
basically i have (state, state code) pairs, that are subsets of country [USA] ->
I am working on some code, basically I have a form. On that form
So i have been creating this framework thing that basically puts together source code
I have read-only access to a database that was set up for a third-party,
So basically the problem is that I have segment of code that needs to
I have a block of code that basically intializes several classes, but they are
I have written a simple class that wraps the JQUeryUI Dialog. It basically looks

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.