Reputation: 795
I created a list using the following, which gets the value from model class which has getter and 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
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.}]}]
how to get data from this and set to a textview and imageview....
Upvotes: 1
Views: 642
Reputation: 481
bundle.putSerializable("object", list.get(position));
Your Serializable stored under "object" is a HashMap not List so you should cast to a Hashmap:
HashMap<String,String> map = (HashMap<String, String>) bundle.getSerializable("object");
Upvotes: 1