我的自定义列表适配器代码...
private final Activity context;
private List<String> list;
public CustomListAdapter(Activity context, List<String> list) {
super(context, R.layout.list_single);
this.context = context;
this.list = list;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView = inflater.inflate(R.layout.list_single, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);
if (list != null) {
for (int i = 0; i < list.size(); i++) {
File imgFile = new File(list.get(i));
if (imgFile.exists()) {
ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
imageView.setImageBitmap(myBitmap);
}
}
}
return rowView;
}
@Override
public int getCount() {
return list.size();
}
}
我收到了一个 imagePath 列表,例如
d:阵列路径/存储/sdcard/DCIM/Camera/IMG_20170210_163055.jpg
d:阵列路径/存储/sdcard/DCIM/Camera/IMG_20170210_163037.jpg
d:阵列路径/存储/sdcard/DCIM/Camera/IMG_20170217_175804.jpg
d:阵列路径/存储/sdcard/DCIM/Camera/IMG_20170217_175802.jpg
d:阵列路径/存储/sdcard/DCIM/Camera/IMG_20170210_163056.jpg
现在我想使用自定义适配器或使用 ArrayAdapter 将这些路径显示到列表视图。