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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:54:29+00:00 2026-06-14T08:54:29+00:00

I’m creating an android app that requires database connectivity, for which I’m using the

  • 0

I’m creating an android app that requires database connectivity, for which I’m using the inbuilt SQLiteDatabase class. My database has been created using the following statement:-

SQLiteDatabase db;
db = openOrCreateDatabase("ContactsMain",SQLiteDatabase.CREATE_IF_NECESSARY,null);
db.execSQL("Create Table Contacts (name Text, phno Text PRIMARY KEY, important Integer)");

‘important’ has values of either 0 or 1, based on whether the contact is important. To update this value, I’m using the following code:

protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    c.moveToPosition(position);
    String ph = c.getString(c.getColumnIndex("phno"));
    ContentValues val = new ContentValues();
    val.put("important",1);
    String query = "update Contacts set important = 1 where phno=" + ph + ";";
    db.update("Contacts", val, query, null);
    c.close();
    db.close();
}       

db and c have been initialized as follows:

SQLiteDatabase db = openOrCreateDatabase("ContactsMain",SQLiteDatabase.CREATE_IF_NECESSARY,null);
Cursor c = db.rawQuery("SELECT * FROM Contacts",null);    

Problem is, when I click on an item in the list, the value of ‘important’ is set to 1 for all contacts, not just the one selected. Could someone help me out here?

  • 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-14T08:54:30+00:00Added an answer on June 14, 2026 at 8:54 am

    You want

    ContentValues val = new ContentValues();
    val.put("important", 1);
    db.update("Contacts", val, "phno=?", new String[] {ph});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I've got a string that has curly quotes in it. I'd like to replace
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build
I have an array which has BIG numbers and small numbers in it. I
I am using Paperclip to handle profile photo uploads in my app. They upload
Let's say I'm outputting a post title and in our database, it's Hello Y’all
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but

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.