Question Detail

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


Thread Reply

Anonymous

- 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();
fragment.setArguments(bundle);

and in Fragment onCreateView method:

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