jeudi 29 janvier 2015

Android Sqlite: get selected spinner's item ID from SQLite table?

I've been trying to find a solution for this issue and so far no luck. I have a spinner located in a Custom Dialog, and this spinner loads info from the table Products. When the user select the spinner, I need to know its ID located in the SQLite table.


I can do that with custom listview using OnItemCLickListener and then grabbing the last 'long' parameter, but it doesn't seem to work with spinner and onItemSelectedListener.


It doesn't work because it gets the Spinner selected item position, and not the actual ID from the SQLite table.


Any tips?


How i am trying to do right now:



final Spinner spn = (Spinner)d.findViewById(R.id.spinner_produtos_listar);
//just a custom method to load data from sql into spinner
loadSpinnerData(spn, (int) id);

spn.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long id) {
PRODUTO_ID = (int)id;

}

public void onNothingSelected(AdapterView<?> arg0) {
}
});


Thanks in advance!


Aucun commentaire:

Enregistrer un commentaire