I'm new to Android dev, and my app crashes when I try to create a new fragment upon clicking my button that has an "onClick" that is called "EnterNameOnClick()" I suspect that the following code from MainActivity might be the problem...
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void EnterNameOnClick(){
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
EnterName_Fragment enterName_fragment = new EnterName_Fragment();
fragmentTransaction.add(android.R.id.content, enterName_fragment);
fragmentTransaction.commit();
}
}
public class EnterName_Fragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.new_user_fragment, container, false);
Spinner spinner = (Spinner) view.findViewById(R.id.movie_spinner);
// Create an ArrayAdapter using the string array and a default spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this.getActivity(), R.array.planets_array, android.R.layout.simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
return view;
}
}
When I am writing the fragmentTransaction.add(android.R.id.content, enterName_fragment), I wonder if the "android.R.id.content" is erroneous? What am I supposed to fill this field with?