Answers for "how to pass data from activity to fragment"

0

pass data from activity to fragment android

Bundle bundle = new Bundle();
bundle.putString("edttext", "From Activity");
// set Fragmentclass Arguments
Fragmentclass fragobj = new Fragmentclass();
fragobj.setArguments(bundle);

And inside fragment:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    String strtext = getArguments().getString("edttext");    
    return inflater.inflate(R.layout.fragment, container, false);
}
Posted by: Guest on January-22-2021
0

Passing data from an activity to a fragment

Bundle bundle = new Bundle();
 String myMessage = "Stack Overflow is cool!";
 bundle.putString("message", myMessage );
 FragmentClass fragInfo = new FragmentClass();
 fragInfo.setArguments(bundle);
 transaction.replace(R.id.fragment_single, fragInfo);
 transaction.commit();
Posted by: Guest on August-15-2021
-2

how to pass data from activity to fragment

passing data from activity to fragment
Posted by: Guest on March-21-2021

Code answers related to "how to pass data from activity to fragment"

Browse Popular Code Answers by Language