Search code examples
androidandroid-fragmentsandroid-bundle

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

}

it is displaying rootView cannot be resolved,i need to add edit text et to string str so that using bundle i can pass it to the next fragment


Solution

  • Try this Add inflater then 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 ;
    }
    }