I want to set the dynamic value for the spinner as its initial value..
If i set that dynamic value then, it doesn't allow me to change to another value..
The dynamic Value of spinner is "AMEX" if i want to change my value as "Discover" that is in Array valu开发者_如何学Goe i cant ,
so pls give me solution here is my code..
spin_type = (Spinner) findViewById(R.id.Spinner_type);
adapter_type = new ArrayAdapter(Credit_Card_Main.this,android.R.layout.simple_spinner_item, array_type);
adapter_type.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spin_type.setAdapter(adapter_type);
spin_type.setOnItemSelectedListener(new OnItemSelectedListener(){
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
spin_type.setSelection(adapter_type.getPosition(Signin.VALUE_type[selected_position]));
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
Thanks
Venkatesh
you can set initial value for spinner by spinner.setPrompt();method .so just set yor dynamic value by that
spin_type.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
for (int i = 0; i < array_type.length; i++) {
if (test_flag_type == false) {
if (array_type[i].toString().equalsIgnoreCase(Credit_Card_List.VALUE_type[Credit_Card_List.selectCard])) {
spin_type.setSelection(adapter_type.getPosition(Credit_Card_List.VALUE_type[Credit_Card_List.selectCard]));
test_flag_type = true;
}
}
}
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
where array_type contains list of credit card names.
I get the first value in array_type[i] here i=0,convert it to the string then compares it with the values i get from Database (i.e) Value_type..
If same it will goes inside if loop and set the value in the position at "i"..
If once value set i change the test_flag_tyype to true so next time it will not go inside the loop since test_flag_type is true..
This is the way i make it to work..
精彩评论