Reputation: 126
I am trying to parse the following Json.
{
"effect_list": [{
"1":[
{
"effects_id":"1",
"effects_name":"Band 1"
},
{
"effects_id":"2",
"effects_name":"Band 2"
}
],
"2": [
{
"effects_id":"4",
"effects_name":"Background Blur"
},
{
"effects_id":"5",
"effects_name":"Blemish Removal"
}
]
}]
}
My BaseAdapter shows only first Item in the ListView. I am trying to retrieve values in Map. During iteration the values gets override.When I print the values, It's printing properly.
MyContactAdapter2.java
public class MyContactAdapter2 extends BaseAdapter {
List<Map<String, List<EffectList>>> contactList;
Context context;
private LayoutInflater mInflater;
// Constructors
public MyContactAdapter2(Context context, List<Map<String, List<EffectList>>> objects) {
this.context = context;
this.mInflater = LayoutInflater.from(context);
contactList = objects;
}
public MyContactAdapter2() {
System.out.println("hai");
}
@Override
public int getCount() {
int count = contactList.size();
System.out.println("Count size" + count);
return count;
}
@Override
public Map<String, List<EffectList>> getItem(int position) {
return contactList.get(position);
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
System.out.println(10);
final MyContactAdapter2.ViewHolder vh;
if (convertView == null) {
View view = mInflater.inflate(R.layout.get_layout_row_view, parent, false);
vh = MyContactAdapter2.ViewHolder.create((RelativeLayout) view);
view.setTag(vh);
} else {
vh = (MyContactAdapter2.ViewHolder) convertView.getTag();
}
for (Map<String, List<EffectList>> map : contactList) {
for (Map.Entry<String, List<EffectList>> entry : map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
System.out.println("key :" + key + "value :" + value);
EffectList item = getItem(position).get(key).get(0);
vh.textViewName.setText(item.getEffectsId());
vh.textViewEmail.setText(item.getEffectsName());
}
}
return vh.rootView;
}
private static class ViewHolder {
public final RelativeLayout rootView;
public final ImageView imageView;
public final TextView textViewName;
public final TextView textViewEmail;
private ViewHolder(RelativeLayout rootView, ImageView imageView, TextView textViewName, TextView textViewEmail) {
this.rootView = rootView;
this.imageView = imageView;
this.textViewName = textViewName;
this.textViewEmail = textViewEmail;
}
public static MyContactAdapter2.ViewHolder create(RelativeLayout rootView) {
ImageView imageView = (ImageView) rootView.findViewById(R.id.imageView);
TextView textViewName = (TextView) rootView.findViewById(R.id.textViewName);
TextView textViewEmail = (TextView) rootView.findViewById(R.id.textViewEmail);
return new MyContactAdapter2.ViewHolder(rootView, imageView, textViewName, textViewEmail);
}
}
}
So my Question is, how can I iterate the "Map" values inside "GetView()" in "BaseAdapter"?
Is it possible to iterate values inside GetView() method in BaseAdapter?
Upvotes: 2
Views: 107
Reputation: 6659
Can't you do:
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// ... blah blah ...
final Map<String, List<EffectList>> effectMap = getItem(position);
for (Map.Entry<String, List<EffectList>> entry : effectMap.entrySet()) {
final String key = entry.getKey();
final List<EffectList> value = entry.getValue();
// ... do stuff ...
}
// ... blah blah
}
?
Upvotes: 2