Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to divide nested ArrayList to the every layout at TabLayout

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);
    }
}

enter image description here

like image 361
salih Avatar asked Oct 27 '15 09:10

salih


1 Answers

I hope I understand your requirements and code correctly. I understand you only have 2 TextViews in the layout for 10 different texts. So...in this case, you need 10 TextViews for the ObjectID, row #, name, age, surname, location, etc. You cannot have only 2 TextViews.

Let's start with this and hopefully the issues will get clarified for all of us.

like image 75
The Original Android Avatar answered Oct 12 '22 15:10

The Original Android