This is what's happening in your current code:
You create the Fragment
In the onCreateView()
method, you get the arguments
You set the arguments in your Activity.
In other words, you're calling the arguments before you've set them. As per the Fragment Documentation, you should be using a static method to instantiate your Fragments. It would look something like the following.
In your Fragment class, add this code
/**
* Create a new instance of UserInfoFragment, initialized to
* show the text in str.
*/
public static MyFragment newInstance(String str) {
MyFragment f = new MyFragment();
// Supply index input as an argument.
Bundle args = new Bundle();
args.putString("edttext", str);
f.setArguments(args);
return f;
}
And now, in your Activity, do the following:
//Bundle bundle = new Bundle();
//bundle.putString("edttext", "From Activity");
//UserInfoFragment fragobj = new UserInfoFragment();
//fragobj.setArguments(bundle);
UserInfoFragment fragobj = UserInfoFragment.newInstance("From Activity");
Notice how now, you don't even need to create a Bundle and set it in your Activity class, it is handled by the static newInstance()
method.