I have two models called Buyer
and Car
, and a custom layout called custom_row
to display the rows of a ListView
.
public class CustomAdapter extends BaseAdapter {
Context c;
ArrayList<Buyer> buyers;
public CustomAdapter(Context c, ArrayList<Buyer> buyers) {
this.c = c;
this.buyers = buyers;
}
@Override
public int getCount() {
return buyers.size();
}
@Override
public Object getItem(int position) {
return buyers.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = LayoutInflater.from(c).inflate(R.layout.custom_row, parent, false);
}
TextView tvBuyerName = (TextView) convertView.findViewById(R.id.tvBuyerName);
TextView tvCarModel = (TextView) convertView.findViewById(R.id.tvCarModel);
final Buyer b = (Buyer) this.getItem(position);
tvBuyerName.setText(b.getBuyerName());
return convertView;
}
}
So far I've only done above code, and I'm only able to display buyer's name. How to create another reference in ArrayList
to model Car
, so that I can get and display the information from both model Buyer
and model Car
in a same ListView
?