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

  • Home
  • SEARCH
  • 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 7011429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:07:34+00:00 2026-05-27T22:07:34+00:00

I am a complete noob with HashMaps and have spent the better part of

  • 0

I am a complete noob with HashMaps and have spent the better part of a week trying to find what I need.

I am successfully parsing a JSON response from an HTTP request. What I’m having trouble with is saving each data variable/value from each JSON row into a HashMap and then retrieving those data values later.

In my for loop where I’m parsing the JSON response, I need to make sure I’m using the correct syntax for the put command.

More importantly, in getBottles() I need to know how to set o1.setname_abbr to the first record in the HashMap for name. I will eventually need to turn that into a for loop and assign all of the names from the JSON response and then get them all back from the HashMap in getBottles().

Many thanks for any assistance!

Here is my code…

    public class Bottles extends ListActivity {
        private int category_id;
        private int subcategory_id;
        String subcategory_idString = "false";
        String postQuery;
        private int bottleID;
        String name_abbr;
        String name_abbrArray[];
        String bottlePicture;
        private ProgressDialog m_ProgressDialog = null;
        private ArrayList<Bottles> m_bottles = null;
        private BottleAdapter m_adapter;
        private Runnable viewBottles;
        ArrayList<HashMap<String, String>> bottleNameArray = new ArrayList<HashMap<String, String>>();
        HashMap<String, String> bottleNamesMap = new HashMap<String, String>();
        String name[];

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            requestWindowFeature(Window.FEATURE_NO_TITLE);
            setContentView(R.layout.bottleslist);

            String result = "";
            Bundle extras = getIntent().getExtras();
            if(extras != null){
                category_id = getIntent().getExtras().getInt("id");
                subcategory_id = getIntent().getExtras().getInt("subid");
                if(subcategory_id==0){
                    subcategory_idString = "";
                }
            }

            InputStream is = null;
            //http post
            try{
                if(subcategory_idString==""){
                    postQuery = "my api call goes here";
                }
                if(subcategory_idString=="false"){
                    postQuery = "different api call goes here";
                }
                HttpClient httpclient = new DefaultHttpClient();
                HttpPost httppost = new HttpPost(postQuery);
                HttpResponse response = httpclient.execute(httppost); 
                HttpEntity entity = response.getEntity();
                is = entity.getContent();
            }catch(Exception e){
                Log.e("log_tag", "Error in http connection "+e.toString());
            }

          //convert response to string
            try{
                BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                        sb.append(line + "\n");
            }
            is.close();
            result=sb.toString();
            }catch(Exception e){
            Log.e("log_tag", "Error converting result "+e.toString());
            }

            try {
                JSONObject row = new JSONObject(result);
                JSONArray array = row.getJSONArray("response name");
                for (int i = 0; i < array.length(); i++) {
                    row = array.getJSONObject(i);
                    bottleID = row.getInt("id");
                    name_abbr = row.getString("name_abbr");
                    bottleNamesMap = new HashMap<String, String>();
                    bottleNamesMap.put("name", name_abbr);
                    bottlePicture = row.getString("bottlePicture");
                }
                }catch(Exception e){
                    Log.e("log_tag", "Error parsing JSON "+e.toString());
                }

            m_bottles = new ArrayList<Bottles>();
            this.m_adapter = new BottleAdapter(this, R.layout.bottlelistimagelayout, m_bottles);
                    setListAdapter(this.m_adapter);

            viewBottles = new Runnable(){
                public void run() {
                    getBottles();
                }
            };
        Thread thread =  new Thread(null, viewBottles, "MagentoBackground");
            thread.start();
            m_ProgressDialog = ProgressDialog.show(Bottles.this,    
                  "Please wait...", "Retrieving data ...", true);
        }
        public class Bottle{
            public String name_abbrArray;
            //public String lastName;
            //public int age;
        }
        private void getBottles(){
            try{
                //will put this into a for loop after I figure out how to reference the HashMap values
                m_bottles = new ArrayList<Bottles>();
                Bottles o1 = new Bottles();
        o1.setname_abbr("I want to get the HashMap value of the first name here");
                o1.setbottlePicture("Pending");
                Bottles o2 = new Bottles();
                o2.setname_abbr("I want to get the HashMap value of the second name here");
                o2.setbottlePicture("Completed");
                m_bottles.add(o1);
                m_bottles.add(o2);
                   Thread.sleep(2000);
                Log.i("ARRAY", ""+ m_bottles.size());
              } catch (Exception e) {
                Log.e("BACKGROUND_PROC", e.getMessage());
              }
              runOnUiThread(returnRes);
          }

        private Runnable returnRes = new Runnable() {

        public void run() {
            if(m_bottles != null && m_bottles.size() > 0){
                m_adapter.notifyDataSetChanged();
                for(int i=0;i<m_bottles.size();i++)
                m_adapter.add(m_bottles.get(i));
            }
            m_ProgressDialog.dismiss();
            m_adapter.notifyDataSetChanged();
            }
          };

        private class BottleAdapter extends ArrayAdapter<Bottles> {

            private ArrayList<Bottles> items;

            public BottleAdapter(Context context, int textViewResourceId, ArrayList<Bottles> items) {
                    super(context, textViewResourceId, items);
                    this.items = items;
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                    View v = convertView;
                    if (v == null) {
                        LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                        v = vi.inflate(R.layout.bottlelistimagelayout, null);
                    }
                    Bottles o = items.get(position);
                    if (o != null) {
                            TextView tt = (TextView) v.findViewById(R.id.toptext);
                            TextView bt = (TextView) v.findViewById(R.id.bottomtext);
                            if (tt != null) {
                                  tt.setText("Name: "+o.getname_abbr());                            }
                            if(bt != null){
                                  bt.setText("Picture: "+ o.getbottlePicture());
                            }
                    }
                    return v;
            }
    }

}
  • 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-27T22:07:35+00:00Added an answer on May 27, 2026 at 10:07 pm

    I think I don’t fully understand your question, but if you add every bottle hashmap to an arraylist (by the way I see you have an ArrayList<Bottle> what should be its purpose, look empty to me).

    You can, then, loop your arraylist containing your hashmaps: arrayListOfBottles.get(position)

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

Sidebar

Related Questions

I'm a complete noob to jquery and jquery ui but have successfully implemented a
I am a complete noob at C (<1 week) and I'm trying to get
complete noob to Haskell here with probably an even noobier question. I'm trying to
I am a complete Noob when it comes to GIT. I have been just
I'm a complete Codeigniter noob. I think I have everything setup properly, and the
I have been looking into CruiseControl configuration recently (I'm a complete CC noob) and
I am a complete noob when it comes to the NoSQL movement. I have
I'm a complete noob to regex and I need help with splitting a string.
Im complete noob to Javascript, but very keen to learn more. I have a
I am a complete noob to c. I have downloaded a code from internet.

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.