我有两个不同大小和不同类型的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;