1. Download our Official Android App: Forums for Android!

Apps Spinner problem

Discussion in 'Android Development' started by Maxxan, Aug 19, 2010.

  1. Maxxan

    Maxxan Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    7
    Joined:
    Aug 19, 2010

    Aug 19, 2010
    7
    0
    5
    Hi!
    I've got a problem when trying to catch the selection of a spinner list item. I've added an OnItemSelectedListener, but it is only fired when a NEW item in the list is selected, not when the same item is selected that was selected before. How do I catch that event?

    Example: Spinner has values A, B, and C, value A is selected by default. If I click the spinner and select A again in the list, OnItemSelectedListener is not fired. But I A is selected and I select B or C in the list, OnItemSelectedListener is fired.

    How do I notice if A is selected again in the list?
     

    Advertisement

  2. meskiukas

    meskiukas Newbie
    Rank:
    None
    Points:
    36
    Posts:
    13
    Joined:
    Aug 20, 2010

    Aug 20, 2010
    13
    1
    36
    Programmer
    Sweden
    Why do you need the event to fire again? It's usually a good thing not to do work when nothing has changed.
     
  3. Maxxan

    Maxxan Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    7
    Joined:
    Aug 19, 2010

    Aug 19, 2010
    7
    0
    5
    The first item is like an "Add items.." options, so when I select that I want to open an input dialog.
     
  4. blundell

    blundell Well-Known Member
    Rank:
    None
    Points:
    38
    Posts:
    124
    Joined:
    Apr 23, 2010

    Apr 23, 2010
    124
    17
    38
    Software Engineer
    UK
    You could: When option A is selected open your dialog and set the spinner to (none selected, d selected) so as if they click A again your onClick will fire
     
  5. Maxxan

    Maxxan Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    7
    Joined:
    Aug 19, 2010

    Aug 19, 2010
    7
    0
    5
    What I tried now was to create a custom adapter, and set the onClick listner for the first view. But if I do it like that, the list is never closed when clicking on the first item.

    Is is possible to programatically close the list?
     
  6. meskiukas

    meskiukas Newbie
    Rank:
    None
    Points:
    36
    Posts:
    13
    Joined:
    Aug 20, 2010

    Aug 20, 2010
    13
    1
    36
    Programmer
    Sweden
    IMHO, you should reconsider having the "Add new item" selected by default, and have the user explicitly press if, if they need to add a new item. If something already is selected, the user won't know that he has to click on it again. So I would either have it selected by default, and have your code that deals with the form submission to see this, and show the dialog, or add a new item, which would be name "Please choose...", or something like that. You will end up with an application that is easier to use.
     
  7. Maxxan

    Maxxan Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    7
    Joined:
    Aug 19, 2010

    Aug 19, 2010
    7
    0
    5
    Ok, that might be a good idea. :)

    But do you know how to create a context menu for a spinner item?
     

Share This Page

Loading...