Hello, I need to load a Spinner
with the data coming from my Database (SQL). For this I have created a class with an id and a description. The problem is that instead of showing the description, in the Spinner
the name of the package is shown to me.
I leave the code just in case. Thank you very much.
private void poblarSpinnerObra(ArrayList<ObrasCuenta> list) {
ArrayAdapter<ObrasCuenta> adapter =
new ArrayAdapter<ObrasCuenta>(MejorasFragment.this.getContext(), android.R.layout.simple_spinner_item, list);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_item);
spinnerObraMej.setAdapter(adapter);
spinnerObraMej.setOnItemSelectedListener(
new AdapterView.OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
if ((pos!=0) && (id!=0)) {
// buscar comprobantes adeudados
Object item = parent.getItemAtPosition(pos);
idSubsistema = ((ObrasCuenta) item).getIdObra();
buscarDeuda();
cargarRecyclerView();
}
}
public void onNothingSelected(AdapterView<?> parent) {}
});
}
With the previous code (taken from the Internet) I try to populate the Spinner with an ArrayList but it is visualized in the following way. The behavior in the event is the desired one. I clarify in case it serves as something that the data is in a Fragment