Findviewbyid With Fragments
I have this problem with fragments.. I wanted to add a drawer menu in my app and than work with fragments. I have this code, and when i putted the fragments 'findviewbyid' didnt wo
Solution 1:
The Fragment
is not a Activity
which means you can not use activity methods or it's lifecycle. This means you cant find views in the onCreate()
method of a Fragment
and you can not use findViewById
on it either.
This is the Android lifecycle https://stackoverflow.com/a/36340059/4467208
and to adjust your code according to that, move your findViews
into onCreateView()
like this
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Viewview= inflater.inflate(R.layout.fragmentLayout, container, false);
nome = (EditText) view.findViewById(R.id.nome);
return view;
}
And so on.
Post a Comment for "Findviewbyid With Fragments"