FindViewbyID with fragments

别来无恙 提交于 2019-12-02 07:00:44
Murat Karagöz

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) {
    View view = inflater.inflate(R.layout.fragmentLayout, container, false);
    nome = (EditText) view.findViewById(R.id.nome);
    return view;
}

And so on.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!