【发布时间】:2015-03-03 19:14:45
【问题描述】:
我有一个类,它在数据库中获取两个字段(名称和图像)并将名称设置为文本视图并将图像设置为图像视图 现在我有图像问题,如何通过存储在数据库中的图像名称将图像设置为图像视图? 请帮帮我!
我的源代码:
public class ListMovie extends BaseAdapter {
private Resources res = null;
private Activity activity;
private ArrayList<HashMap<String, String>> data;
private LayoutInflater inflate;
ViewHolder holder;
public ListMovie(Activity a, ArrayList<HashMap<String, String>> d) {
// TODO Auto-generated constructor stub
activity = a;
data = d;
inflate = (LayoutInflater) activity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return data.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int arg0, View view, ViewGroup arg2) {
// TODO Auto-generated method stub
View v1 = view;
if (v1 == null) {
v1 = inflate.inflate(R.layout.item, null);
holder = new ViewHolder();
holder.txt_name = (TextView) v1.findViewById(R.id.item_name);
holder.img = (ImageView) v1.findViewById(R.id.item_img);
v1.setTag(holder);
} else {
holder = (ViewHolder) v1.getTag();
}
HashMap<String, String> song = new HashMap<String, String>();
song = data.get(arg0);
holder.txt_name.setText(song.get("name"));
return v1;
}
static class ViewHolder {
TextView txt_name;
ImageView img;
}
}
【问题讨论】:
-
“图像名称”是指存储图像文件的路径?
-
不只是存储图像名称并将图像放入drawable
标签: android image android-imageview