How to pass value from Activity to Fragment? I hope someone can help.
Asked
Active
Viewed 1,725 times
-1
-
1Add code that you have try – MilapTank Sep 09 '14 at 07:38
-
1Can you add a little more description? and what have you tried? – MysticMagicϡ Sep 09 '14 at 07:38
-
This is another post, http://stackoverflow.com/questions/25726834/how-to-change-pages-in-viewpager-with-different-content This is my problem. – user3632453 Sep 09 '14 at 07:39
-
do you mean `pass` or `parse`?? add code which you have already tried – Akhil Jain Sep 09 '14 at 07:39
-
This is another post, http://stackoverflow.com/questions/25726834/how-to-change-pages-in-viewpager-with-different-content This is my problem. I want to get value from activity and set in the fragment. – user3632453 Sep 09 '14 at 07:42
-
possible duplicate of [Proper way to give initial data to fragments](http://stackoverflow.com/questions/10798489/proper-way-to-give-initial-data-to-fragments) – 0101100101 Sep 09 '14 at 07:48
1 Answers
1
In Activity
Bundle bundle=new Bundle();
bundle.putString("name", "From Activity");
//set Fragmentclass Arguments
Fragmentclass fragobj=new Fragmentclass();
fragobj.setArguments(bundle);
Fragment onCreateView
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
String strtext=getArguments().getString("name");
return inflater.inflate(R.layout.fragment, container, false);
}

Naveen Tamrakar
- 3,349
- 1
- 19
- 28
-
-
create a constrater on fragment and get data in constrater object – Naveen Tamrakar Sep 09 '14 at 07:55