Passing Multiple Lists into ArrayAdapter

后端 未结 4 1851
隐瞒了意图╮
隐瞒了意图╮ 2021-01-17 00:59

I start of with this in Activity:

adapter = new ItemAdapter(Items.this, items, totals);
        setListAdapter(adapter);

Now here is ItemAd

4条回答
  •  無奈伤痛
    2021-01-17 02:04

    Add one more argument in your constructor-- to accommodate the additional List; however don't pass that additional list in the super call.

    Then in the getView method access that second list. Take a look at the code:

      public class NotificationsAdapter extends ArrayAdapter {
          private Context context;
          private List list;
          private List listTimeStamp;      
    
          public NotificationsAdapter(Context context, List resource,List timeResource) {
              super(context, R.layout.notification_list_item, resource);
              this.context = context;
              this.list = resource;
              this.listTimeStamp= timeResource;
          }      
    
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              View rowView = inflater.inflate(R.layout.notification_list_item, parent, false);      
    
              TextView textViewMessage = (TextView) rowView.findViewById(R.id.text_view_notifications_list_item);
              textViewMessage.setText(list.get(position));      
    
              ImageView imageView = (ImageView) rowView.findViewById(R.id.logo_notifications_list_item);
              imageView.setImageResource(R.drawable.iconsmall);      
    
              TextView textViewTimeStamp = (TextView) rowView.findViewById(R.id.time_stamp_notifications_list_item);
              textViewTimeStamp.setText(listTimeStamp.get(position));      
    
              return rowView;
          }
      }
    

提交回复
热议问题