Edittext View Returns Null
I have two activities - a Home fragment activity, and a normal Options activity. In my home fragment activity, I'm trying to update an EditText View using data retrieved from the O
Solution 1:
Edit:
Move this snippet:
if (getActivity().getIntent() != null && getActivity().getIntent().getExtras() != null) {
String[] prelimUserArray = getActivity().getIntent().getExtras().getStringArray("userArray");
updateUserData(prelimUserArray);
}
to the onViewCreated
method, which will be called after the view has been inflated.
publicvoidonViewCreated(View view, @Nullable Bundle savedInstanceState){
// Your code here
}
Check this image for more information about the Fragment's lifecycle.
Make sure that you are calling your updateUserData
method after the Fragment's onCreateView()
callback has been triggered.
Try using getView()
instead of getActivity()
as mentioned in this answer.
getActivity()
returns the Activity hosting the Fragment, whilegetView()
returns the view you inflated and returned by onCreateView. The latter returns a value != null only after onCreateView returns.
Also, as mentioned in the comments, check if you indeed have the EditText
with an id Input_Name.
Post a Comment for "Edittext View Returns Null"