[英]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.