所以我有一个类型列表" Item_Array_Class"在我的主屏幕上
以下是该课程:
public class Item_Array_Class {
String vendor;
String category;
String price;
Bitmap item_Image;
int Index;
public Item_Array_Class(String vendor, String category, String price, Bitmap item_Image, int Index) {
this.vendor = vendor;
this.category = category;
this.price = price;
this.item_Image = item_Image;
this.Index = Index;
}
public String get_vendor() {
return vendor;
}
public String get_category() {
return category;
}
public String get_price() {
return price;
}
public Bitmap get_Image() {
return item_Image;
}
public int get_Index() { return Index; }
}
我想在制作自定义listview
时访问此列表,以便我可以从数组中提取图像和供应商并显示它们,因为自定义视图只是ImageView
和{{{ 1}}。
以下是我自定义列表视图类的代码:`
textView
我希望做的事情就像是:
class custom_list_view extends ArrayAdapter
{
public custom_list_view(Context context, HomeScreen.Item_Array_Class[]
item_array)
{
super(context, R.layout.custom_list_view, item_array);
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
LayoutInflater inflater = LayoutInflater.from(getContext());
View customView_Var = inflater.inflate(R.layout.custom_list_view, parent, false);
TextView item_title_TV = (TextView) customView_Var.findViewById(R.id.custom_list_title);
ImageView item_image = (ImageView) customView_Var.findViewById(R.id.custom_list_image);
//get the data from the array here <-------
String vendor = item_array.get(position).get_Vendor(); //Cannot resolve symbol 'item_array'
item_title_TV.setText();
item_image.setImageBitmap();
return customView_Var;
}
}
然而,我似乎无法访问String vendor = item_array.get(position).get_Vendor();
我在构造函数中传递它。我可以打电话给item_array
但是我没办法只获得图像和供应商。任何帮助将不胜感激。
TL; DR:如何在我的自定义列表视图的类中访问我的HomeScreens自定义列表,从列表中的每个插槽中提取图像和供应商,以放在{的每个项目的图像视图和文本视图中{1}}。
答案 0 :(得分:0)
这样做......
class custom_list_view extends ArrayAdapter
{
private List<HomeScreen.Item_Array_Class> item_array
item_array
public custom_list_view(Context context, List<HomeScreen.Item_Array_Class>
item_array)
{
super(context, R.layout.custom_list_view, item_array);
this.item_array = item_array;
}
现在尝试获取
item_array.get(position)
答案 1 :(得分:0)
我可以调用getItem(position)但是我无法只获取Image和供应商。
是的,你确实有办法...
首先,修复你的班级定义
extends ArrayAdapter<Item_Array_Class>
然后
Item_Array_Class item = getItem(position);
String vendor = item.get_Vendor();