I try to implement a ListView with specific icon, title and subtitle at each item.
The data of all items is in an ArrayList of objects from following class:
class ItemObject{
String title="";
String subTitle="";
String unit="";
int icon;
int quantity;
int parentID;
int orderInList;
}
ArrayList<ItemObject> listViewData;
Here is the code I used first:
class ExtendedArrayAdapter<String> extends ArrayAdapter<String>{
private Context context;
private String[] items;
public ExtendedArrayAdapter(Context context, String[] items){
super(context,-1,items);
this.context = context;
this.items=items;
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.lv_item_bg,parent,false);
TextView itemTitle = (TextView)itemView.findViewById(R.id.itemTitle);
TextView itemSubTitle = (TextView)itemView.findViewById(R.id.itemSubTitle);
ImageView itemIcon = (ImageView)itemView.findViewById(R.id.itemIcon);
itemTitle.setText(listViewData.get(position).title);
itemSubTitle.setText(listViewData.get(position).subTitle);
itemIcon.setBackgroundResource(listViewData.get(position).icon);
return itemView;
}
}
But the problem regarding this custom ArrayAdapter is that ExtendedArrayAdapter needs a String[] of items to get the number of ListView items.
Question:
Is it possible to change the ExtendedArrayAdapter class to get directly the length of ListView instead of String[] items?
EDIT1:
In super(), I can use only following set of parameters:

and all need Array<String> or List<String>. So I cannot use my ArrayList of objects here.