我的rootView中有错误

时间:2015-09-15 05:52:35

标签: android android-fragments android-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);
}

}

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

2 个答案:

答案 0 :(得分:0)

你需要先膨胀它:

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

答案 1 :(得分:0)

试试这个添加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 ;
}
}