-3
 @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 无法解析,我需要将编辑文本 et 添加到字符串 str 以便使用 bundle 我可以将它传递给下一个片段

4

2 回答 2

0

你需要先给它充气:

View rootView = inflater.inflate(R.layout.fragment_currentmovie, container, false);
...
return rootview;
于 2015-09-15T05:54:38.890 回答
0

试试这个 Add inflater 然后返回。

  @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 ;
}
}
于 2015-09-15T05:57:25.643 回答