Friday 15 July 2011

android - How to retrieve one info from spinner (mysql_id) -



android - How to retrieve one info from spinner (mysql_id) -

first of all, stackoverflow website accessed @ university =d. well, have spinner info (i trying message app). let's see code:

public void fillemployee() { employeedao dao = new employeedao(getbasecontext()); spndestinationmsg = (spinner) findviewbyid(r.id.spndestinationmsg); string query = "select * employee order mysql_id asc"; cursor cursor = dao.cacthbycursor(query); string[] = { "mysql_id", "name" }; int[] = { r.id.txtmysql_id_employee, r.id.txtname_employee }; simplecursoradapter advertisement = new simplecursoradapter(getbasecontext(), r.layout.item_employee, cursor, from, to, 0); spndestinationmsg.setadapter(ad);}

inside object employee have next fields:

private long id; private long mysql_id; private string name; private int updatestatus;

ok, must set mysql_id employee object value coming spinner (the mysql_id comes webservice when start app first time). need mysql_id.

for example:

employeedao emp1 = new employeedao(getbasecontext()); emp1.setmysql_id(spndestinationmsg.getadapter().getitemid(spndestinationmsg .getselecteditemposition()));

the problem have because spinner value of array or value of _id. need have access mysql_id. how can this? there way access info stored in spinner. because within cursor selected table. how access other values? if want grab value of updatestatus example? (i click spinner item , grab value - mysql_id, _id, updatestatus, etc. possible?). ps: without using onselectedlistener because user may not alter spinner. help.

you can utilize onselectedlistener, despite feelings user not making change.

public class spinneractivity extends activity implements onitemselectedlistener { ... public void onitemselected(adapterview<?> parent, view view, int pos, long id) { // item selected. can retrieve selected item using // parent.getitematposition(pos) } public void onnothingselected(adapterview<?> parent) { // interface callback } }

if user didn't alter anything, "onnothingselected" callback saves you

android spinner

No comments:

Post a Comment