I am using nested ArrayList for Tablayout. Each element of ArrayList populate each Tab. Tab count is change according to parent arraylist's size. For example When parent ArrayList's size 2 , tab count 2; when size 3 tab count 3..etc..In order to explain this situation is difficult, I prepared expalantion image..
Image 1
This image represents general apperance. I want to populate this TextViews with ArrayLists each element
Image 2
This image represents my data type; keys and values ArrayList is nested arraylist and they contain arraylist in each index.
Image 3 - Image 4 - Image 5
This images represents how tabLayouts used to be.I want my data looks like this images.
So issue is PopUpDetailsAdapterPlanT Class;
When I use codes below each row populate with same item. For this example every row writes last element of ArrayList (Location - Minnesota) How can I handle this issue. Thanks for helpings
public class PopUpDetailsAdapterPlanT extends ArrayAdapter {
Context context;
private ArrayList<ArrayList<Object>> keys;
private ArrayList<ArrayList<String>> values;
public PopUpDetailsAdapterPlanT(Context context, ArrayList<ArrayList<Object>> keys, ArrayList<ArrayList<String>> values) {
super(context,R.layout.popupdetails_listview_simpleitem);
this.keys = keys;
this.values = values;
this.context = context;
}
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.popupdetails_listview_simpleitem, null);
}
TextView tv1 = (TextView) v.findViewById(R.id.hashmapKeys);
TextView tv2 = (TextView) v.findViewById(R.id.hashmapValues);
for (int i = 0; i < keys.size(); i++) {
ArrayList<Object> mKeys = new ArrayList<>(keys.get(i));
ArrayList<String> mValues = new ArrayList<>(values.get(i));
for (int j = 0; j <mKeys.size() ; j++) {
tv1.setText(String.valueOf(mKeys.get(j)));
tv2.setText(String.valueOf(mValues.get(j)));
}
}
return v;
}
@Override
public int getCount() {
return keys.get(0).size();
}
@Override
public Object getItem(int position) {
if (position >= keys.size())
return values.get(position);
return keys.get(position);
}
}
tv1.setText(keys.get(tabIndicator).get(position)); tv2.setText(values.get(tabIndicator).get(position));
– Silversteinfor
to loop on your ArrayLists. use iterator, it is much more efficient . – Signefor (ArrayList<Object> mKeys : keys) {for (Object object : mKeys) {}}
– Signe