嗨,下面是我的 baseadapter 课程,但它不能正常工作:
private static class MyBaseAdapter extends BaseAdapter {
private Context context;
private LayoutInflater inflater;
private MyBaseAdapter(Context context, FlipViewController controller) {
inflater = LayoutInflater.from(context);
this.context = context;
}
@Override
public int getCount() {
return Globals.list_album.size();
}
@Override
public Object getItem(int position) {
return position;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View layout = convertView;
if (convertView == null )
{
if (Globals.list_album.get(position).no_of_images == 1) {
layout = inflater.inflate(R.layout.single_image_adapter, null);
}
else if(Globals.list_album.get(position).no_of_images == 2) {
layout = inflater.inflate(R.layout.two_image_adapter, null);
}
else if(Globals.list_album.get(position).no_of_images == 3) {
layout = inflater.inflate(R.layout.three_image_adapter, null);
}
else if(Globals.list_album.get(position).no_of_images == 4) {
layout = inflater.inflate(R.layout.four_image_adapter, null);
}
else if(Globals.list_album.get(position).no_of_images == 5) {
layout = inflater.inflate(R.layout.five_image_adapter, null);
}
}
return layout;
}
}
我想根据 Globals.list_album 中的图像数量将布局加载到每个位置。但它不能正常工作。它不适用于 no_of_images = 5 和 2,因为我在列表中有这样的值。目前我的 no_of_images 值为 4、3、1、2 和 5。所以它应该显示布局four_image_adapter、three_image_adapter、one_image_adapter、two_image_adapter 和five_image_adapter。但它显示了four_image_adapter、three_image_adapter、one_image_adapter、four_image_adapter和three_image_adapter。所有布局都有根据图像数量的图像视图。有人能告诉我我必须做什么吗?