我的 rootView 有错误

i have an error in my rootView

 @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);
}

}

它显​​示 rootView 无法解析,我需要将编辑文本等添加到字符串 str 以便使用 bundle 我可以将它传递到下一个片段

您需要先给它充气:

View rootView = inflater.inflate(R.layout.fragment_currentmovie, container, false);
...
return rootview;

试试这个 添加充气器然后 return。

  @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 ;
}
}