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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:36:27+00:00 2026-06-06T13:36:27+00:00

Good day, Basically i am looking for a way to retrieve and save a

  • 0

Good day, Basically i am looking for a way to retrieve and save a key-value pair with respect to a column item in sqlite database so that i can update a listview.

Example: if i have a column named “group” with an item entry named “family”; with respect to that item, i would like to be able to save or retrieve a list of contacts (name and number) just for that item “Family”. same for another item entry.

what would be the best way to do this?. i tried saving the contacts details in a column on the table, using an ArrayList of a Hashmap via json. but having troubles doing it this way. i tried this:

when saving:

//already have the name and number from using the android contacts api

    final ArrayList<HashMap<String,String>> contacts = new ArrayList<HashMap<String,String>>();     
    HashMap<String, String> map = new HashMap<String,String>();
            map.put(name, number);
            contacts.add(map);

            JSONObject json_contacts = new JSONObject();

                try {
            json_contacts.put("contacts_Arrays", new JSONArray(contacts));
                    arraylist_to_string = json_contacts.toString();

                } catch (JSONException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            ContentValues values = new ContentValues(); 
            values.put(ContactDB.GROUP, groupname);
            values.put(ContactDB.GROUP_CONTACTS, arraylist_to_string);

            Log.d(TAG, "Successfully updating contacts for group");
            dbadapter.updateGroup(rowId, values);
            cursoradapter.notifyDataSetChanged();

when retrieving in my bindview method:

String contactDetails = cursor.getString(cursor.getColumnIndex(ContactDB.GROUP_CONTACTS));

        if(contactDetails != null){
            try {
                JSONObject json = new JSONObject(contactDetails);
                JSONArray json_array = json.optJSONArray("contacts_Arrays");

                for(int i=0; i < json_array.length(); i++){
    LinkedHashMap<String,String> map = new LinkedHashMap<String, String>();
            Iterator<String> myIterator = map.keySet().iterator();
                    while(myIterator.hasNext()){
                       key = (String)myIterator.next();
                       value = (String)map.get(key);

                       holder.contact_name.setText(key);
                       holder.contact_number.setText(value);                           
                       notifyDataSetChanged();

                    }
                }


            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }else{
            return;
        }
    }

Not having any luck with it at all and not sure if its the correct way to do that in the first place. what would the best way to structure the database table. should i create a contact object and store it or is there a better way? Thank you

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

    Just by looking at your code, multiple HashMap instances in a List might be a memory overkill, depending on the size of your stored data.

    Since you want to store key-value pairs, a relational database (like SQLite is one) is most often not the right decision. Android has the "Shared Preferences" to store simple key-value pairs (with primitive data-types).


    If you want/need to implement it with SQLite, you should go the relational way. If I understood your question correctly, you would have tables like the following:

    Table "Groups"
    +----------+------------+
    | group_ID | group_name |
    +----------+------------+
    | 1        | Family     |
    | 2        | Work       |
    +----------+------------+
    
    Table "Contacts"
    +----------+------------+--------+
    | name     | number     | group  |
    +----------+------------+--------+
    | Jon      | 0173401... | 1      |
    | James    | 057123...  | 2      |
    | Lukas    | 012343...  | 2      |
    +----------+------------+--------+
    

    From this table, you can query that "James" and "Lukas" are members of the "Work"-group. You could then query all members of the "Work" group by simply searching for entries with the group-column set to the value presented in the group-table (which is 2 for the "Work"-group).

    With this system, you can then add new groups and contacts and put contacts in on (or multiple) groups.

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

Sidebar

Related Questions

Good Day. I'm looking for switch replacement in jQuery. Basically, I have no idea
Good day folks, I'm in a need of a bit of guidance. Basically, I'm
Good Day, I'm currently designing database structure for a website of mine. I need
Good day, I'm having a problem with asp.net 2.0 viewstate. Basically, I want to
Good day, I have a fairly simple question to experienced C# programmers. Basically, I
Good day shell lovers! basically i have two files: frequency.txt: (multiple lines, space separated
Good day I'm trying to solve an issue with foreign key relationship between three
Good Day All we are trying to do is inside a trigger make sure
Good day. I have little usage of Flash CS4, however i have to build
Good day everyone, I am building a page in ASP.NET, and using Master Pages

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.