如何将位图和字符串插入到哈希图中



嗯,我一直在尝试将来自网络的图像插入到哈希图中。当我使用可绘制文件中的图像时,一切都很好。但是当我尝试使用Bitmap对象和字符串时,在add中给我这个错误:The method add(HashMap<String,String>) in the type ArrayList<HashMap<String,String>> is not applicable for the arguments (HashMap<String,Object>)

HashMap<String, Object> map = new HashMap<String, Object>();
                    map.put(TAG_ID_AU, id);
                    map.put(TAG_NAME, name);
                    map.put(TAG_BIRTHDAY_DATE, birthday_date);
                    map.put(TAG_IMAGE, myBitmap);
                    map.put(TAG_DAY_LEFT, day_left);
                    productsList.add(map);

myBitmapBitmap其余的都是字符串。

编辑

很抱歉这个问题,并为您提供答案,现在我可以将 url 中的图像放在我的修改适配器中,我只需要解决该错误。

尽管您尚未发布相关代码,但从错误消息中很容易看出您的ArrayList类型是错误的。它应该是

ArrayList<HashMap<String,Object>> productsList

而不是电流

ArrayList<HashMap<String,String>> productsList

创建对象

public class myProduct {
    private String id;
    private String name;
    private String mybitmap; 
public myProduct(String id,String name,Bitmap mybitmap){
    setId(id);
    setName(name);
    setBitmap(mybitmap); 
}
    public String getName(){
        return this.name;
    }
    public  void setName(String  name){
        this.name=name;
    }
    public String getId(){
        return this.id;
    }
    public void setId(String id){
        this.id =id;
    }
    public void setBitmap(Bitmap mybitmap){
        this.mybitmap=mybitmap;
    }
    public Bitmap getBitmap(){
        return this.mybitmap;
    }
}

之后将其添加到您的活动中

List<myProduct> list=new ArrayList<myProduct>();
myProduct mp=new myProduct("0","name..",Bitmap);
list.add(mp);

您可以像这样访问您的数据:

String name=list.get(int).getName();

最新更新