使用两个不同的arraylist填充一个自定义适配器

时间:2015-01-28 14:26:55

标签: android listview arraylist

我有两个不同大小和不同类型的arraylist(AL1和AL2)。我想在同一个列表视图中显示两个列表。 请有人指导我。

mainActivity:

ArrayList<String> foodList = new ArrayList<String>();
ArrayList<LifeHabit> habitList = new ArrayList<LifeHabit>();

actionLV = (ListView)findViewById(R.id.habit_list);
foodLV = (ListView)findViewById(R.id.food_list);

actionLV.setAdapter(new ActionListAdapter(habitList,"LogActivity"));
foodLV.setAdapter(new FoodListAdapter(foodList));

getView for FoodAdapter:

    LayoutInflater inflater = (LayoutInflater)parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View view = (View)inflater.inflate(R.layout.food_list_item, null);
        TextView actionName = (TextView)view.findViewById(R.id.food_name);
        actionName.setText(foodList.get(position));
return view;

ActionAdapter的getView:

    LayoutInflater inflater = (LayoutInflater)parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View view = (View)inflater.inflate(R.layout.action_list_items, null);

        final TextView actionName = (TextView)view.findViewById(R.id.action_name);

        try {
            actionName.setText(userHabits.get(position).getDisplayName());
        } catch (Exception e) {
            e.printStackTrace();
        }
return view;

0 个答案:

没有答案