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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:48:04+00:00 2026-05-28T04:48:04+00:00

I’m not entirely sure which part of my code is making this happen. This

  • 0

I’m not entirely sure which part of my code is making this happen. This is my first attempt at coding in SQLite with Android and I’m using ContentValues to input records into the database. I get no errors or anything and data is inserted properly, however I’m getting 5 ListView entries for each record when I pull them from the database. It’s either that I misunderstand how data is entered when using ContentValues and .insert to place the data in the database or I’m doing something wrong when retrieving data from the database.

Here is the code I’m using to insert data into the database.

DatabaseHelper helper = new DatabaseHelper(this);
    database = helper.getWritableDatabase();

    ContentValues cv=new ContentValues();

    cv.put(myName, titleText);
    cv.put(myFileName, filenameText);
    cv.put(myRecDate, recordedText);
    cv.put(myPubDate, publishedText);
    cv.put(myDescription, DescriptionText);

    database.insert(myTable, castName, cv);
    database.insert(myTable, castFileName, cv);
    database.insert(myTable, castRecDate, cv);
    database.insert(myTable, castPubDate, cv);
    database.insert(myTable, castDescription, cv);

    database.close();

Here is my code for populating my ListView.

DatabaseHelper helper = new DatabaseHelper(this);
    database = helper.getWritableDatabase();
    Cursor data = database.query("myDb", fields, null, null, null, null, null);
    dataSource = new SimpleCursorAdapter(this, R.layout.row, data, fields, new int[] {R.id.idText, R.id.name, R.id.description});

    final ListView view = getListView();

    view.setHeaderDividersEnabled(true);
    view.addHeaderView(getLayoutInflater().inflate(R.layout.row, null));
    setListAdapter(dataSource);

    database.close();

Since data is successfully being inserted, I don’t think there’s anything wrong with my DatabaseHelper class. Any advice is greatly appreciated.

  • 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-28T04:48:04+00:00Added an answer on May 28, 2026 at 4:48 am

    ContentValues is supposed to represent a single record. So you have this part where you are creating the record from your object. These should be a mapping of column name to column value.

    cv.put(myName, titleText);
    cv.put(myFileName, filenameText);
    cv.put(myRecDate, recordedText);
    cv.put(myPubDate, publishedText);
    cv.put(myDescription, DescriptionText);
    

    And then here you are inserting the same record 5 times. I’m assuming your second parameters here are the column names.

    database.insert(myTable, castName, cv);
    database.insert(myTable, castFileName, cv);
    database.insert(myTable, castRecDate, cv);
    database.insert(myTable, castPubDate, cv);
    database.insert(myTable, castDescription, cv);
    

    In Android, you just need to specify the table name, myTable in this case, the second parameter should be null, and the final parameter should be the ContentValues object.

    So the correct way to do this would be:

    ContentValues cv = new ContentValues();
    cv.put(nameColumn, nameValue);
    cv.put(fileNameColumn, fileNameValue);
    ... etc ...
    
    database.insert(tableName, null, cv);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm making a simple page using Google Maps API 3. My first. One marker
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

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.