我现在有一个ListView,它从一个SimpleAdapter获取信息,它将文本输入到TextViews中。但是,我现在想要将一个ImageView添加到ListView中,并从ListView加载图像,并且仍然将文本加载到TextView中。
有人知道我是怎么做到的吗?也许在这种情况下不应该使用SimpleAdapter?
谢谢,丹尼尔
发布于 2013-12-19 09:52:07
使用本教程完成此操作,并修改了LazyAdapter类以编辑TextViews。
http://www.technotalkative.com/android-asynchronous-image-loading-in-listview/
发布于 2013-12-17 14:54:30
你必须做以下事情:
适配器的示例。
public class Onadapter extends BaseAdapter {
String[] label;
String[] image;
public Onadapter(Context context,String[] label,String[] image)
{
this.context=context;
this.image = image;
this.label = label;
}
private class ViewHolder{
ImageView img;
TextView label;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.list_layout, null);
holder = new ViewHolder();
holder.label=(TextView) convertView.findViewById(R.id.textview);
holder.img = (ImageView) convertView.findViewById(R.id.imageview);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
AQuery aq = new AQuery(convertView);
aq.id(holder.label).text(label[position]);
aq.id(holder.img).image(image[position], true, true, 0, 0, null, AQuery.FADE_IN_NETWORK, 1.0f);
return convertView;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return image1.length;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}通过下载jar版本(首选)导入AQuery库,并将其粘贴到libs文件夹中。
为标签和图像url传入两个字符串数组。AQuery库也可以缓存图像!
发布于 2013-12-17 14:35:43
SimpleAdapter只能处理文本。如果您想要一个每个项目都包含不同图像的列表,则必须创建一个自定义适配器。
https://stackoverflow.com/questions/20636840
复制相似问题