N
N
Nuslagar2016-02-25 20:03:58
Java
Nuslagar, 2016-02-25 20:03:58

Passing Hashmap elements to another activity?

I implemented the method of adding elements to the listview through the HashMap, made it so that when you click on the element, another activity opens, how now to transfer the value contained in the HashMape to the new activity?

flat = new ArrayList<HashMap<String,Object>>();      
    HashMap<String, Object> hm;

    hm = new HashMap<String, Object>();
    hm.put(id, "S 5");
    hm.put(name, " Название1");                 
    hm.put(clas, " Класс:");        
    hm.put(view, " инф");
    hm.put(price, " 500  ");
    hm.put(img, R.drawable.kras40_main);

    flat.add(hm);                            

    hm = new HashMap<String, Object>();
    hm.put(name, " Название2");
    hm.put(clas, " Класс:");
    hm.put(img, R.drawable.lebed64_main);

    flat.add(hm);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2016-02-25
@zagayevskiy

In Java, it's generally not customary to store data in this way. You need to make a class that will have all these fields, this class can also implement the Parcelable interface, then you can push it into Intent.putExtra(), start the activity, pull it out using Intent.getExtras().getParcelable() and get profit. There are other ways, but you seem to need to master this one first.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question