Android 我的根视图中有一个错误
}Android 我的根视图中有一个错误,android,android-fragments,android-bundle,Android,Android Fragments,Android Bundle,} 它显示无法解析的rootView,我需要将编辑文本et添加到字符串str,以便使用bundle我可以将其传递到下一个片段您需要首先将其充气: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { et=(EditText)rootView.findViewById(
它显示无法解析的rootView,我需要将编辑文本et添加到字符串str,以便使用bundle我可以将其传递到下一个片段您需要首先将其充气:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
et=(EditText)rootView.findViewById(R.id.et1);
String str=et.getText().toString();
Fragment frag=new Fragment();
Bundle bundle1=new Bundle();
bundle1.putString("name", str);
frag.setArguments(bundle1);
getFragmentManager().beginTransaction().add(R.id.container_body, frag).commit();
return inflater.inflate(R.layout.fragment_currentmovie, container, false);
}
试试这个添加充气器,然后返回
View rootView = inflater.inflate(R.layout.fragment_currentmovie, container, false);
...
return rootview;
按如下方式操作:查看rootView=inflater.inflate(R.layout.fragment\u currentmovie,container,false)和return
rootView
fromonCreateView
rootView应该是您在最后一行中正在充气和返回的,我是否需要更换返回充气器。充气(R.layout.fragment\u currentmovie,container,false);使用return RootView返回充气器。充气(R.layout.fragment\u currentmovie,container,false);返回rootview
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_currentmovie, container, false);
et=(EditText)rootView.findViewById(R.id.et1);
String str=et.getText().toString();
Fragment frag=new Fragment();
Bundle bundle1=new Bundle();
bundle1.putString("name", str);
frag.setArguments(bundle1);
getFragmentManager().beginTransaction().add(R.id.container_body, frag).commit();
return rootView ;
}
}