putSerializable in fragment

386 views Asked by At

i want to go to send my data to other activity(fragment) by using this code //activity1.class

    Fragment fragment = null;
    Bundle args = new Bundle();       
    args.putSerializable("content_news",oslist.get(position));
    fragment = new Detail_News_fragment();
    fragment.setArguments(args);
    FragmentManager frgManager = getFragmentManager();
    frgManager.beginTransaction().replace(R.id.content_frame, fragment)
            .commit();

by retrieving data activity2

   Intent i = getActivity().getIntent();
   i.getSerializableExtra("ct_detail_eng");
   HashMap<String, String> stud = ( HashMap<String, String> )
   i.getSerializableExtra("content_news");
   String Title =  stud.get(News.TAG_TITLE_News);
   Topic = (TextView)view.findViewById(R.id.TitleDetail);
    Topic.setText(Title);

but it is not work at all please help, thx for advance

1

There are 1 answers

0
Alexander On

In your Activity 1 put extra data in the Intent which calls Activity 2

Intent intent = new Intent(this, Activity2.class);
intent.putExtra(...)
startActivity(this, intent);

Then in Activity 2 retrieve the intent using getIntent() and the data using Intent.getExtra()

Then you may want to put the retrieved data into your fragment in Activity 2.