android - get id of spinner item clicked which is set at server side -


i getting json response php server

{ "optrdata":[ {"operator_id":"1","operator_name":"airtel","operator_status":"1"},{"operator_id":"2", "operator_name":"idea","operator_status":"1"},....]}

i able set operator_name data on spinner.

now question want operator_id of operator_name when i/user click on operator name how can that.

create model class following.

public class operator{   public string id,name,status; } 

now create arraylist this,

arraylist<operator> operatorslist = new arraylist<operator>();

at time of parsing object

for(int =0;i<jsonarray.lenth();i++){   operator op = new operator();   op.name = //get string here   op.id = //get json object   op.status = //get json object   operatorlist.add(op); } 

and fill spinner looping through array list , after selecting item data according position of selection can data arraylist with

operator op = operatorslist.get(positionofspinnerselection)

and id , name

string name = op.name; string id = op.id; 

Comments