Spinner problems

by Danny » Sun, 15 Mar 2009 06:48:59 GMT


Sponsored Links
 Hi all:
I have some problems with spinners
1. I have 3 spinners: type_spinner, from_spinner, to_spinner.

Problem: from_spinner and to_spinner does not display correctly what
are selected AFTER switching to landscape mode ( or portrait mode ) by
pressing Ctrl + F11.
The position selected of from_spinner and to_spinner are correct after
switching ( Tested ), BUT the values displayed on the spinner are
WRONG after switching( resetted to pos# 0 ).

Example:

Before switching

Type Spinner:  TYPE2
From_spinner:   CALIFORNIA ( pos#2 )
To_spinner:    NEWYORK  (pos#3)

After switching ( Ctrl + F11 )

Type Spinner:  TYPE2
From_spinner:  OREGON ( pos# 0 ) - If open the spinner(click), it is
selected at pos#2
To_spinner:    OREGON ( pos#0 ) - If open the spinner, it is selected
at pos#3)



Here is the code:

private Spinner type_spinner;
private Spinner from_spinner;
private Spinner to_spinner;

type_spinner = (Spinner) findViewById(R.id.type_spinner);
        ArrayAdapter<CharSequence> type_adapter =
ArrayAdapter.createFromResource(this, R.array.types,
android.R.layout.simple_spinner_item);
        type_adapter.setDropDownViewResource
(android.R.layout.simple_spinner_dropdown_item);
        type_spinner.setAdapter(type_adapter);

I want to setup from_spinner, and to_spinner from the selection of
type_spinner, so I call my setSpinner function from the onItemSelected
event of type_spinner

type_spinner.setOnItemSelectedListener(new
AdapterView.OnItemSelectedListener(){
                        @Override
                        public void onItemSelected(AdapterView<?> adapter, View 
view,
                                        int position, long arg3) {

                                clearScreen();
                                setSpinner(position);
                        }

                        @Override
                        public void onNothingSelected(AdapterView<?> arg0) {
                                type_spinner.setSelection(LIQUID_TYPE);

                        }
         });

 private void setSpinner(int type){
        switch(type){
                case TYPE1:
                         from_adapter = ArrayAdapter.createFromResource(this,
R.array.type1,
 
android.R.layout.simple_spinner_item);
                         to_adapter = ArrayAdapter.createFromResource(this, 
R.array.type1,
 
android.R.layout.simple_spinner_item);
                         break;
                case TYPE2:
                        from_adapter = ArrayAdapter.createFromResource
(this, R.array.type2,
 
android.R.layout.simple_spinner_item);
                         to_adapter = ArrayAdapter.createFromResource(this, 
R.array.type2,
 
android.R.layout.simple_spinner_item);
                         break;

         }
           from_adapter.setDropDownViewResource(
 
android.R.layout.simple_spinner_dropdown_item);
            to_adapter.setDropDownViewResource(
 
android.R.layout.simple_spinner_dropdown_item);

            from_spinner.setAdapter(from_adapter);
            to_spinner.setAdapter(to_adapter);
            from_spinner.setSelection(2); // For testing - Array has >
10 items
            to_spinner.setSelection(3); //For testing - Array has > 10
items

Please let me know how to fix this. Thanks for your help.

--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. emulator gets lost from Eclipse

Hello,

After a while the emulator gets lost from the Eclipse Devices space.
What might be wrong? (on win7)
-- 
Mrton

-- 

2. showDialog() and "requestFeature() must be called before adding content" Error

I've seen this error when trying to set the view on a Dialog after it's been
created. Setting the view as part of the construction process using the
Builder makes it go away.

Maybe try creating the ProgressDialog with the constructor first ("new
ProgressDialog(title, msg, ...), then using the show() method with no
arguments?

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
http://sites.google.com/site/rezmobileapps/treking







> 

3. 3G connection sometimes missing from emulator

4. Please Suggest, Where can we buy Android phones.

5. Does anyone know how to publish an application to the OPhone's Market?

6. SQLite database location restriction

7. Google Voice on Droid counts as Verizon voice calls