Class I want to check the spinner place, so I can only move to another page if I have selected something, I would use the option selected in Spinner instead in another class.
public static Spinner lugar;
public static EditText a;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inicial);
Spinner lugar = findViewById(R.id.spinneronde);
EditText a = findViewById(R.id.editText);
String[] lugares = new String[]{ "Em casa", "No trabalho","Na rua",
"Outro"};
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
R.layout.support_simple_spinner_dropdown_item, lugares);
lugar.setAdapter(adapter);
Button continuar = findViewById(R.id.Continuar_Button);
Inicial user = new Inicial();
}
public void continuar(View view)
{
if (lugar.getSelectedItem() != null && a != null)
{
startActivity(new Intent(this, Menu.class));
}
else
{
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setMessage("Por Favor preencha todas as perguntas. :)");
alertDialog.setCancelable(true);
}
}
Class I want to get the option that was selected, but, I can not get the value of the Spinner place to use in that.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu);
Spinner lug = Inicial.lugar;
String selectedop = lug.toString();
if(selectedop == "Em casa")
{
AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
alertDialog.setMessage("CASA :)");
alertDialog.setCancelable(true);
}
}
}