我正在尝试将一组图像显示为ListView到ListView,有人可以帮助我吗?
这是我的CustomList.java
public class CustomList extends ArrayAdapter<String>{
private final Activity context;
private final String[] web;
private final Integer[] imageId;
public CustomList(Activity context, String[] web, Integer[] imageId) {
super(context, R.layout.mylist, web);
this.context = context;
this.web = web;
this.imageId = imageId;
}
@Override
public View getView(int position, View view, ViewGroup parent) {
LayoutInflater inflater = context.getLayoutInflater();
View rowView= inflater.inflate(R.layout.mylist, null, true);
TextView txtTitle = (TextView) rowView.findViewById(R.id.txt);
ImageView imageView = (ImageView) rowView.findViewById(R.id.img);
txtTitle.setText(web[position]);
imageView.setImageResource(imageId[position]);
return rowView;
}
}
以下是mainActivity.java的一些代码
ListView list;
ImageView image;
String[] web = {
"Google Plus",
"Twitter",
"Windows",
"Bing",
"Itunes",
"Wordpress",
"Drupal"
} ;
Integer[] imageId = {
R.drawable.image1,
R.drawable.image2,
R.drawable.image3,
R.drawable.image4,
R.drawable.image5,
R.drawable.image6,
R.drawable.image7
};
CustomList adapter = new CustomList(this, web, imageId);
list=(ListView)findViewById(R.id.list);
list.setAdapter(adapter);
我的所有图片都是Bitmap类型,我希望将它们放在imageId数组上以显示在Custom ListView上
答案 0 :(得分:0)
使用 int [] 数组而不是 Integer [] 数组,
tooltips=false
也会在 CustomList.java 文件
中进行相应的更改