English 中文(简体)
Set the initial value of Android Spinner with some dynamic value
原标题:

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 value 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

最佳回答
    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..

问题回答

you can set initial value for spinner by spinner.setPrompt();method .so just set yor dynamic value by that





相关问题
How to set Spinner default value to null?

I m trying to get a Spinner to load up with no selected value. Once the user selects a value it then takes them to another page. This is proving to be a problem because at present, the page just ...

Accessing objects dynamically created with an adapter

I ve created a dynamic ListView with TextViews and Spinners, using a SimpleAdapter and a ViewBinder. How can I access a Spinner value after the user had selected it? I think I need to create ...

How to show divider between spinner items?

I using listviews and expandedviews that has dividers and I can set them but on spinner its looks like it is no divider between items. Someone that has a idea of how to fix this?

热门标签