I have a Spinner
in a Fragment
, that when I click on an item of Spinner
leads me to another Fragment
. But when I run the app, it goes directly to the first item in Fragment
. It does not show me the Fragment
that has the Spinner
, but it opens the first option of Spinner
.
I add the code of Spinner
public class Bajar_Peso extends Fragment {
public Bajar_Peso() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view;
view = inflater.inflate(R.layout.fragment_bajar__peso, container, false);
Spinner spinnerA , spinnerB;
String[] Frutas;
String[] Vegetales;
Button secreto;
secreto=(Button)view.findViewById(R.id.btn_secreto);
spinnerA = (Spinner)view.findViewById(R.id.spinner_Frutas);
spinnerB=(Spinner)view.findViewById(R.id.spinner_Vegetales);
Frutas = getResources().getStringArray(R.array.Bjar_PesoA);
Vegetales=getResources().getStringArray(R.array.Bjar_PesoB);
//SPINNER PARA LAS FRUTAS.
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getActivity().getApplicationContext(),android.R.layout.simple_list_item_1,Frutas);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerA.setAdapter(arrayAdapter);
//SPINNER PARA LOS VEGETALES
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getContext(),android.R.layout.simple_list_item_1,Vegetales);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinnerB.setAdapter(adapter);
//SELECCION DE LAS FRUTAS
//SELECCION DE LOS VEGETALES
spinnerB.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
if(position==0)
{
getActivity().getSupportFragmentManager().beginTransaction().replace(R.id.content_main,new BP_Zanahorias()).commit();
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
secreto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
}
});
return view ;
}
}