Question Detail

I want to pass data Activity to Fragment. How can I do this? 

Thread Reply


- 1 years ago

From Activity you send data with intent as:

String str="This is my Message";
Bundle bundle = new Bundle();
bundle.putString("message", str);
// set Fragmentclass Arguments
Fragmentclass fragment = new Fragmentclass();

and in Fragment onCreateView method:

public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
    String strtext = getArguments().getString("message");    
    return inflater.inflate(R.layout.fragment_lay, container, false);