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 ).


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,

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

                        public void onItemSelected(AdapterView<?> adapter, View 
                                        int position, long arg3) {


                        public void onNothingSelected(AdapterView<?> arg0) {


 private void setSpinner(int type){
                case TYPE1:
                         from_adapter = ArrayAdapter.createFromResource(this,
                         to_adapter = ArrayAdapter.createFromResource(this, 
                case TYPE2:
                        from_adapter = ArrayAdapter.createFromResource
(this, R.array.type2,
                         to_adapter = ArrayAdapter.createFromResource(this, 


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

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


Other Threads

1. Suggestions to remove on boot Service (aimed to detect incoming calls) and others

Hi all,

I have gone through many threads in this group about avoiding the use
of everlasting Services, Timer/TimerTask sleep issues and detecting
phone calls, but not finding the answers I am looking for this app, I
will really appreciate any help you can provide me.

I am working on an App to detect incoming calls and when the call time
is equal to 5 minutes indicate the user by vibrating the phone.

In my strategy I am creating a Receiver that listens for
RECEIVE_BOOT_COMPLETED action and launch an everlasting Service which
sets up a PhoneStateListener.

1) Is there any other strategy to be always listening for incoming
calls and thus avoide to using an on boot created Service? (besides
the Service eventually gets killed and I am not able to detect
incoming calls)

A first approach I took here was setting up a Timer and TimerTask when
CALL_STATE_RINGING state was detected and after 5 min (if the call
continues) vibrate the phone for 2 seconds. However sometimes the
timer phone vibrates after an hour a call was placed (the vibration
happens in the run() TimerTask method. I know Android can go to sleep
and that could be the reason my timer is not run on time but...
2) How can Android be slept if I am in a call? Is the call just
handled by the modem or how come?

Next, to overcome this issue I tried preventing the Service from going
to sleep by putting it in foreground state calling
startForeground(NOTIFICATION_ID , notification), still the same
behaviour the timer is run long after the call was placed...
3) does startForeground prevent Android going to sleep or it is just
aimed to keep the Service's process in memory?
4) A wake lock would do this job ? (I have not tried this)

Encouraged by many post I tried using an Alarm and it works (thought I
do not want to use it because I think it should be possible to
accomplish with something lighter) but when the phone vibrates it just
keeps vibrating till I remove the phone from my cheek (the screen is
turned on again)
5) Why? Is it  that Android started vibrating the phone and then went
to sleep?... so the vibration is turned off when Android awakes, when
the screen is turned on again?
6? Ideas of how to stop the timer?

Thanks a lot for your support!
Juan Garibay


2. how to deal with button clickevent in a listview?

Please find my working code snippet below:

// get a reference to the ListView
listView = (ListView) findViewById(android.R.id.list);
// single click event
listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {

My list view works with the customized adapter.


3. Android News: over 1 billion apps downloaded from Android Market

4. Samsung Galaxy S News: Update available in Korea and Expect 10 Mil sales worldwide

5. Text box +radio menu(pop-up)

6. WTest : Test send from Opera Mini 5.1

7. VOOT: Yang Penasaran dengan Kotak Kartu SIM