简体   繁体   English

如何使用Arraylist中的bundle使用putserializable获取传递的值 <Hashmap<String,String> &gt;

[英]How to get valus passed using putserializable using bundle from Arraylist<Hashmap<String,String>>

I created a list using the following, which gets the value from model class which has getter and setter. 我使用以下命令创建了一个列表,该列表从具有getter和setter的模型类中获取值。

    int k = model.getChildren().size();
    for(int i=0;i < k;i++) {
        HashMap<String, String> map = new HashMap<String, String>();
        galleryChildModel = model.getChildren().get(i);
        map.put("caption", galleryChildModel.getImagecaption());
        map.put("imageurl", galleryChildModel.getImageurl());
        list.add(map);
    }

then im passing this value to next fragment using this setOnItemClickListener 然后我使用此setOnItemClickListener将此值传递给下一个片段

       gridchild.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Fragment fragment = new GalleryDetailFragment();
            Bundle bundle = new Bundle();
            bundle.putSerializable("object", list.get(position));
            fragment.setArguments(bundle);
            FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction.replace(R.id.container_body, fragment);
            fragmentTransaction.addToBackStack(null);
            fragmentTransaction.commit();
        }
    });

i'm getting the value in the respective fragment using 我正在使用以下方法获取相应片段中的值

   Bundle bundle = this.getArguments();

    if (bundle != null) {
          ArrayList<HashMap<String, String>> maps = (ArrayList<HashMap<String, String>>) bundle.get("object"); // here i cannot cast the value to hashmap or any list. im really stuck here can anyone help me out with this
    }

the value im getting is like this 我得到的价值是这样的

Bundle[{ object=[{ imageurl= http://futhead.cursecdn.com/static/img/15/players/20801.png,caption=Ronaldo .}]}] 捆绑包[{object = [{imageurl = http://futhead.cursecdn.com/static/img/15/players/20801.png,caption=Ronaldo

how to get data from this and set to a textview and imageview.... 如何从中获取数据并设置为textview和imageview。

bundle.putSerializable("object", list.get(position));

存储在“对象”下的Serializable是HashMap而不是List,因此您应将其强制转换为Hashmap:

HashMap<String,String> map = (HashMap<String, String>) bundle.getSerializable("object");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从Hashmap获取ArrayList <String String> - How to get ArrayList from Hashmap<String String> 使用HashMap(String,ArrayList <String> ) - Using HashMap(String, ArrayList<String>) 如何获取 HashMap <String,ArrayList<String> &gt; 从给定的字符串 Java - How to get an HashMap<String,ArrayList<String>> from a given String Java 从HashMap获得价值 <String, ArrayList<String> &gt; - Get value from HashMap<String, ArrayList<String>> 如何迭代ArrayList <HashMap<String, String> &gt;在使用JSTL的jsp页面中 - How to iterate ArrayList<HashMap<String, String>> in a jsp page using JSTL 如何马歇尔 HashMap <string, arraylist<string> &gt; 使用 JAXB</string,> - How to Marshall HashMap<String, ArrayList<String>> using JAXB 排序ArrayList <HashMap<String, String> &gt;使用价值 - sort ArrayList<HashMap<String, String>> using value 使用SparseIntArray而不是HashMap <Integer, Integer> 使用putSerializable - Using SparseIntArray instead of HashMap <Integer, Integer> with putSerializable 如何使用morphia映射字符串的HashMap和字符串的ArrayList - How to map HashMap of String and ArrayList of Strings using morphia 如何从ArrayList添加值 <HashMap<String, String> &gt; menuItems = new ArrayList <HashMap<String, String> &gt;编辑文本 - How to add values from ArrayList<HashMap<String, String>> menuItems = new ArrayList<HashMap<String, String>> to Edit Text
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM