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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:27:04+00:00 2026-06-01T17:27:04+00:00

I have written a CustomAdapter to display a list of hash key+value items as

  • 0

I have written a CustomAdapter to display a list of hash key+value items as a list. But I am stuck on the line below.

label.setText(my_VALUES[0])

Class two is my CustomAdapter and I am passing it a hashMap

public MyCustomAdapter(DynamicLists dynamicLists, int row, HashMap<String,String> data)

here I combine key+value pairs and I assign them to an array called my_VALUES. But I don’t know if this is correct?

How can I print out each KEY+VALUE pair as a seperate item in getview. at the moment I can only use label.setText(my_VALUES[0])

Thanks

graham
package gb.org;

//lists are not checkboxes 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;


//class 1 
public class DynamicLists extends ListActivity { 



//class 2 
public class MyCustomAdapter extends BaseAdapter { 
    private HashMap<String,String> mData = new HashMap<String,String>();
    private String[] mKeys;
    String[] my_VALUES = new String[100];



    public MyCustomAdapter(DynamicLists dynamicLists, int row, HashMap<String,String> data){ 
    mData = data;
    mKeys = mData.keySet().toArray(new String[data.size()]);
    Log.d(TAG, "INSIDE ADAPTER HELLO WORLD " + map.entrySet()); 


    String[] array = new String[map.size()];
    int count = 0;
    String combined="";
    for(Map.Entry<String, String> entry : map.entrySet()){
        combined="A"+entry.getKey()+"B"+entry.getValue();

    my_VALUES[count]=combined;
    Log.d(TAG, " my_VALUES " + my_VALUES);
    count++;


    }


}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
    String key = mKeys[position];
    String Value = getItem(position).toString();

    //do your view stuff here
    Log.d(TAG, "inside getview  ");
    View row=convertView;

if (row==null){
    LayoutInflater inflater=getLayoutInflater();
    row=inflater.inflate(R.layout.row, null);
}

TextView label =(TextView)row.findViewById(R.id.blocked);
label.setText(my_VALUES[0]);  //printing out the last value 

return row;   

}
@Override
public int getCount() {

    // TODO Auto-generated method stub
    return mData.size();
}
@Override
public Object getItem(int position) {
    // TODO Auto-generated method stub
    return mData.get(mKeys[position]);
}
@Override
public long getItemId(int position) {
    // TODO Auto-generated method stub
    return position;
}


}  //end of class 2 



private static final String TAG = "Example";


//class 1 


public static  HashMap<String, String> map = new HashMap<String, String>(); 

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   //tie data to list, call constructor MyCustomAdapter 
   //populate the list. ArrayAdapter takes current class, layout and array
   map.put("year", "Apple");    
   map.put("make", "Mango");     
   map.put("model", "Grape");    
   map.put("style", "Orange");     
   map.put("series", "Peach"); 
   Log.d(TAG, "HELLO WORLD " + map.entrySet());    
   //link to my adapter
   setListAdapter(new MyCustomAdapter(DynamicLists.this, R.layout.row, map));

}


@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
// TODO Auto-generated method stub
//super.onListItemClick(l, v, position, id);
String selection = l.getItemAtPosition(position).toString();
Toast.makeText(this, selection, Toast.LENGTH_LONG).show();


}


} //end of class 1
  • 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-01T17:27:06+00:00Added an answer on June 1, 2026 at 5:27 pm

    See if this works.

    I only changed 2 things:
    1) how my_VALUES is instantiated
    2) label.setText(my_VALUES[position]);

    public class DynamicLists extends ListActivity { 
    
    
    
    //class 2 
    public class MyCustomAdapter extends BaseAdapter { 
        private HashMap<String,String> mData = new HashMap<String,String>();
        private String[] mKeys;
        String[] my_VALUES;
    
    
        public MyCustomAdapter(DynamicLists dynamicLists, int row, HashMap<String,String> data){ 
        mData = data;
    
        my_VALUES = new String[mData.size()];
    
    
        mKeys = mData.keySet().toArray(new String[data.size()]);
        Log.d(TAG, "INSIDE ADAPTER HELLO WORLD " + map.entrySet()); 
    
    
        String[] array = new String[map.size()];
        int count = 0;
        String combined="";
        for(Map.Entry<String, String> entry : map.entrySet()){
            combined="A"+entry.getKey()+"B"+entry.getValue();
    
        my_VALUES[count]=combined;
        Log.d(TAG, " my_VALUES " + my_VALUES);
        count++;
    
    
        }
    
    
    }
    
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
        String key = mKeys[position];
        String Value = getItem(position).toString();
    
        //do your view stuff here
        Log.d(TAG, "inside getview  ");
        View row=convertView;
    
    if (row==null){
        LayoutInflater inflater=getLayoutInflater();
        row=inflater.inflate(R.layout.row, null);
    }
    
    TextView label =(TextView)row.findViewById(R.id.blocked);
    label.setText(my_VALUES[position]);  //printing out the last value 
    
    return row;   
    
    }
    @Override
    public int getCount() {
    
        // TODO Auto-generated method stub
        return mData.size();
    }
    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return mData.get(mKeys[position]);
    }
    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }
    
    
    }  //end of class 2 
    
    
    
    private static final String TAG = "Example";
    
    
    //class 1 
    
    
    public static  HashMap<String, String> map = new HashMap<String, String>(); 
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       //tie data to list, call constructor MyCustomAdapter 
       //populate the list. ArrayAdapter takes current class, layout and array
       map.put("year", "Apple");    
       map.put("make", "Mango");     
       map.put("model", "Grape");    
       map.put("style", "Orange");     
       map.put("series", "Peach"); 
       Log.d(TAG, "HELLO WORLD " + map.entrySet());    
       //link to my adapter
       setListAdapter(new MyCustomAdapter(DynamicLists.this, R.layout.row, map));
    
    }
    
    
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    //super.onListItemClick(l, v, position, id);
    String selection = l.getItemAtPosition(position).toString();
    Toast.makeText(this, selection, Toast.LENGTH_LONG).show();
    
    
    }
    
    
    } //end of class 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a very simple CTE expression that retrieves a list of all
Have written the following code: m_selectCategoryTableWidget = new QTableWidget; m_selectCategoryTableWidget->setRowCount(0); m_selectCategoryTableWidget->setColumnCount(2); m_selectCategoryTableWidget->setHorizontalHeaderLabels(QStringList()<<tr(Category)<<tr(Number of items));
I have written a perl code for processing file 'Output.txt' which has below Content.
Have written some RoR sites in the past, but never bothered too much at
I have written a code function validate() { if(document.getElementById(<%=txtSearch.ClientID %>).value==) { message=Enter the User
i have written a code for insertion sort but it is nt sorting.. kindly
I have written the code for getting the blank cell information but the problem
I have Written the code to store the bitmap Image in sdcard But I
I have written code for finding the diameter of binary tree. But I am
I have written a webmethod that returns the list of the Users althought the

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.