Good day, Hope title is not confusing and i can be clear here. I have a custom ArrayAdapter with TextViews and ImageViews. now i want one of the TextView to be populated by values from a HashMap which have the 2nd columns as the Keys. the structure is just like this..
image1 shop text2
image2 cars text2
image3 House text2
image4 boats text2
In this example, the 1st and 2nd columns have already been populated with arrays in the ArrayAdapter. so i want the text2, to be populated with a HashMap of values of which column2 are the keys. an example is, if there are 30 shops, we will have
image1 shop 30
code is :
Resources rsc = getActivity().getResources();
String[] options = rsc.getStringArray(R.array.item_title);
TypedArray icons = rsc.obtainTypedArray(R.array.item_title_color);
HashMap<String,String> map = new HashMap<String,String>();
MyAdapter adapter = new MyAdapter(getActivity(), R.layout.listview_custom_item, options, icons, map);
list.setAdapter(adapter);
MyAdapter class:
class MyAccountsAdapter extends ArrayAdapter<Object> {
private LayoutInflater mInflater;
private int ViewResourceId;
private String[] mstring;
TypedArray icons;
HashMap<String, String> infomap = new HashMap<String,String>();
public MyAdapter(Context context, int textViewResourceId, String[] string, TypedArray icons, HashMap<String, String> map) {
super(context, textViewResourceId, string);
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mstring = string;
this.icons = icons;
ViewResourceId = textViewResourceId;
infomap.putAll(map); //another hashmap here
}
@Override
public int getCount(){
return mstring.length;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
convertView = mInflater.inflate(ViewResourceId, null);
ImageView imageview = (ImageView)convertView.findViewById(R.id.list_image_id);
TextView text_title = (TextView)convertView.findViewById(R.id.list_text_id);
TextView text_info = (TextView)convertView.findViewById(R.id.list_textinfo_id);
imageview.setImageDrawable(icons.getDrawable(position));
text_title.setText(mstring[position]);
Log.d(TAG, "strings are" + text_title.getText().toString());
// so how do i populate text_info here to correspond with text_title;
return convertView;
}
any ideas? or is there a better way to do this like combine them all into one?.. any help is highly appreciated. Thank you
Try this below code :