RodyRed
RodyRed

Reputation: 43

How to insert Bitmap and Strings into HashMap

Well, I've been trying to insert images from the the Web into the hashmap. When I use images from drawable file, everything goes ok. But when I try to use a Bitmap object and String give me this error in the 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);

myBitmap is a Bitmap the rest are all strings.

EDITED

Sorry for this Question and Tank you for the answers, now i can put the images from the url in my modify adapter, I only needed to resolve that error.

Upvotes: 0

Views: 3721

Answers (2)

Charaf Eddine Mechalikh
Charaf Eddine Mechalikh

Reputation: 1248

create your object

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;
    }

}

after that add this to your activity

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

you can access your data like this :

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

Upvotes: 1

Robby Cornelissen
Robby Cornelissen

Reputation: 97302

Although you haven't posted the relevant code, from the error message it's easy to tell that the type of your ArrayList is wrong. It should be

ArrayList<HashMap<String,Object>> productsList

instead of the current

ArrayList<HashMap<String,String>> productsList

Upvotes: 1

Related Questions