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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:54:06+00:00 2026-05-26T21:54:06+00:00

Here’s what I’m trying to do: – Retrieve a Map of key-value pairs from

  • 0

Here’s what I’m trying to do:
– Retrieve a Map of key-value pairs from a SharedPreferences object (User#, Name)
– write those key-value pairs into an ArrayList such that I can
– use them to populate a ListView with each row containing BOTH the key and the value like so:

  1. User 1 – Joe R.

  2. User 2 – Frank B.

etc


UPDATE:
so after taking a good long look at the SimpleAdapter class, and talking with some wiser more knowledgable folks – I’m a lot closer than I was… but still not all the way there.

here’s what I have now:

public class LogHistory extends ListActivity {

static final ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
private static final String KEY = null;
private static final String VALUE = null;

public void onCreate(Bundle b) {
    super.onCreate(b);
    setContentView(R.layout.log_history);

    SharedPreferences logPrefs = getSharedPreferences(LoginField.PREFSNAME, 0);
    Map<String, ?> logMap = logPrefs.getAll();

    for (Map.Entry<String, ?> e : logMap.entrySet()) {
        HashMap<String, String> row = new HashMap<String, String>();
        String mKey = e.getKey();
        String mValue = (String) e.getValue();
        row.put(KEY, mKey);
        row.put(VALUE, mValue);
        list.add(row);

        // FOR DEBUGGING PURPOSES
        makeToast(mKey);
        makeToast(mValue);
    }

    SimpleAdapter adapter = new SimpleAdapter(
        this,
            list,
            R.layout.list_item,
            new String[] { KEY, VALUE },
            new int[] {R.id.item1, R.id.item2}
    );

    setListAdapter(adapter); 

This sort of works – but only half way… what I get as a result is a list of the VALUES in both columns…

HOWEVER the makeToast function returns the proper values for both the KEY and the VALUE – so the problem must be in the SimpleAdapter method yes??

assistance would be great – homework is due tonight! :-0

  • 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-26T21:54:07+00:00Added an answer on May 26, 2026 at 9:54 pm

    You need to search for “custom listview”, “listview custom adapter” and those things. “two line listview item layout”…

    See this example. There are others on Google.

    Basically, you can create a ArrayList<Hashmap<String,String>>, which is your data container. You add values to that creating as many HashMap<String, String> objects as you need and using list.add(yourHashMap), where list is the ArrayList.

    At the end you feed that to a SimpleAdapter (there are other methods, but this works without much trouble).

    Check the docs to see how each thing works exactly.


    You are nulling your index keys. Put a name into those final Strings.

    This sort of works – but only half way… what I get as a result is a list of the VALUES in both columns…
    HOWEVER the makeToast function returns the proper values for both the KEY and the VALUE – so the problem must be in the SimpleAdapter method yes??

    As I said, no. When you do this:

    row.put(KEY, mKey);
    row.put(VALUE, mValue);
    

    You are not providing a meaninful difference between KEY and VALUE, because both are null. It’s something like putting all things into the same column.

    Your mistake into reasoning that is because the Toast test you created yourself test only the correctness of the values, not the columns:

    makeToast(mKey);
    makeToast(mValue);
    

    In that you test only the values. 😉 You assume that the columns are right, and that the mistake could only be in the values, which is exactly the opposite.

    First rule of dealing with computers: computers never assume LOL. 😉

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

Sidebar

Related Questions

Here I am trying to retrieve the response from the server and display it,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Here is the code in a function I'm trying to revise. This example works
Here is the code: create table `team`.`User`( `UserID` bigint NOT NULL AUTO_INCREMENT , `Username`
Here is the script I'm using, copied directly from Google: <script type=text/javascript> var _gaq
Here is the problem that I am trying to solve. I have two folders
Here's a piece of code I copied from http://www.schillmania.com/content/projects/javascript-animation-1/demo/ Very simple JS animation: function
Here's my database: id name parent_id 1 Computers NULL 2 Apple 1 3 Books
Here is my query: SELECT * FROM [GeoName] WHERE ((-26.3665122100029-Lat)*(-26.3665122100029-Lat))+((27.5978928658078-Long)*(27.5978928658078-Long)) < 0.005 ORDER BY
Here is what is supposed to happen: The moment the user chooses an option

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.