Access Fragment View from Activity's onCreate

纵然是瞬间 提交于 2019-11-28 04:22:44

Update your views in onCreateView().

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
    Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.event_log, container, false);
    TextView tv = (TextView) view.findViewById(R.id.text);
    tv.setText("hello world");
    return view;
}

Or if your changes depend on Activity your Fragment is attached to, use onActivityCreated().

@Override
public void onActivityCreated (Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    TextView tv = (TextView) getView().findViewById(R.id.text);
    tv.setText(getActivity.getSomeText());
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!