I am creating an android application in which I have to use spinner. I want to set a specific tag with every spinner value. For example spinner have three values low,high and very high want to set three tags 100 , 200 , 300. When user select high. I want the value 200 which is store. I have implemented simple spinner , done this with radio buttons but don't know how to do this task with spinners.Kindly help.
by getting the spinner position you can set value. Spinner position will start from 0.
spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
if(spinner.getSelectedItemPosition() == 0){
value = 100;
}else if(spinner.getSelectedItemPosition() == 1){
value = 200;
}else if(spinner.getSelectedItemPosition() == 2){
value = 300;
}
}
}
Use this:
int i=100;
spinnerId.setOnItemSelectedListener(this)
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
switch (arg0.getId()) {
case R.id.spinnerId:
if(arg2==0){
i=100;
}else if(arg2==1){
i=200;
}else{
i=300;
}
break;
default:
break;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.