1
Good afternoon, I have a simple form in my android app, where the user writes name and register an alert, but in the alert frequency field I inserted a spinner(selectbox android) with options of numbers that are strings.
txtFrequencia.setOnItemSelectedListener((AdapterView.OnItemSelectedListener) this);
List<String> frequencia = new ArrayList<String>();
frequencia.add("2");
frequencia.add("4");
frequencia.add("6");
frequencia.add("8");
frequencia.add("10");
frequencia.add("12");
frequencia.add("24");
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, frequencia);
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
txtFrequencia.setAdapter(dataAdapter);
This is the part where I declare the spinner, but the problem is happening in my class that registers in the database, not sure what to insert in it, I’m using getOnItemSelectedListener() to try to get the value but it’s not working, follow the code:
private long loadType() {
Type type = new Type();
millisIdentificador = Calendar.getInstance().getTimeInMillis();
type.setContent("Alerta;" + String.valueOf(millisIdentificador) + ";" + txtNomeAlerta.getText().toString()
+ ";" + (btnTodoDia.isChecked() ? 1 : 0) + ";" + (btnFimdeSemana.isChecked() ? 1 : 0)
+ ";" + Integer.parseInt(txtFrequencia.getOnItemSelectedListener().toString()) + ";"
+ Integer.parseInt(txtQuantComprimidos.getText().toString()) + ";"
+ Integer.parseInt(txtQuantDias.getText().toString()));
type.setComentarCard(0);
type.setCompartilharCard(0);
type.setCurtirCard(0);
return dataStoreType.addType(type);
}
Does anyone have any idea how I can put the correct value of the spinner position.