我有一个这样的 Listfragment :
private ArrayList<String>images;
private View view;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
view = inflater.inflate(R.layout.activity_torrent_detail_images, container, false);
SetAdapter();
return view;
}
public void SetImages(ArrayList<String> images) {
this.images = images;
}
public void SetAdapter() {
if(images!= null && view != null) {
if(this.getActivity() != null) {
this.setListAdapter(new ImageAdapter(this.getActivity(),this.images));
}
}
}
这是我的适配器:
public class ImageAdapter extends ArrayAdapter<String> {
private final Context context;
private final ArrayList<String> images;
App app;
public ImageAdapter(Context context,
ArrayList<String> images) {
super(context, R.layout.search_row, images);
this.context = context;
this.images = images;
app =((App)context.getApplicationContext());
}
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.imagesrow, parent, false);
ImageView img = (ImageView)rowView.findViewById(R.id.imgImage);
app.imageLoader.displayImage(images.get(position), img);//this load the image from the http
return rowView;
}
}
最后,在我的活动中
fragImages.SetImages(ListImage);
问题是列表视图只显示第一张图片。我查看了 ListImage 并且它包含 3 个项目,因此列表视图应该显示 3 个图像。我错过了什么吗?多谢。