Android Community
Results 1 to 7 of 7

Thread: Spinner help

  1. #1
    Join Date
    Feb 2009
    Location
    West Lafayette, IN
    Posts
    21

    Default Spinner help


    I am working on my first program in Android and have encountered a problem. I am using spinners to call up other layouts/windows and have been using onWindowFocusChanged. Every time I close the program or call up the menu to revert to the main screen it crashes with an error that says it has stopped unexpectedly.
    I have been trying to figure this out for days now so any help would be appreciated.

  2. #2
    Join Date
    Sep 2008
    Location
    The Boonies of Pinal County, Arizona
    Posts
    1,186

    Default Re: Spinner help

    What do the logs say? From the Eclipse, get to the DDMS perspective, then click on the 'Logcat' tab. There should be an exception thrown and a stack trace.
    I blame this man for most programming problems.

  3. #3
    Join Date
    Feb 2009
    Location
    West Lafayette, IN
    Posts
    21

    Default Re: Spinner help

    the error says " uncaught handler: thread main exiting due to uncaught exception" then " java.lang.NullPointerException" and then it lists at locations. do you want those?

  4. #4
    Join Date
    Sep 2008
    Location
    The Boonies of Pinal County, Arizona
    Posts
    1,186

    Default Re: Spinner help

    If they're not making sense to you, sure, go ahead and post them.
    I blame this man for most programming problems.

  5. #5
    Join Date
    Feb 2009
    Location
    West Lafayette, IN
    Posts
    21

    Default Re: Spinner help

    most of them make sense, the majority have to deal with onWindowFocusChanged. Is there a better/other way to code when a spinner selection has been made besides this?

  6. #6
    Join Date
    Sep 2008
    Location
    The Boonies of Pinal County, Arizona
    Posts
    1,186

    Default Re: Spinner help

    The Spinner class supports a View.OnClickListener being set, have you tried that?
    I blame this man for most programming problems.

  7. #7

    Default Re: Spinner help


    Quote Originally Posted by boilermaker View Post
    most of them make sense, the majority have to deal with onWindowFocusChanged. Is there a better/other way to code when a spinner selection has been made besides this?
    The onWindowFocusChanged documentation says this:

    onWindowFocusChanged(boolean) Called when the window containing the view gains or loses focus.

    I expect you have a listener to handle views gaining focus, but not the window losing focus? (for example when the menu appears, the menu will have focus)

    Quote Originally Posted by ickyfehmleh View Post
    The Spinner class supports a View.OnClickListener being set, have you tried that?
    This is correct, if you want to listen to events on something then find the smallest listener that covers only that thing's events.

    Something like this:

    Code:
    Spinner s = new Spinner(this);
    s.setOnClickListener(new OnClickListener(){
        public void onClick(View v) {
                    // do something                
        });
    (Note define the spinner in xml, don't be naughty like me)

    Whenever the spinner is clicked you will get the onClick method getting called, and v contains the view object that called it

    Eg:
    Log.d("spinner1",((Spinner)v).getSelectedItem().to String()); (not too useful but I don't know what class your data is.)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •