Android Code Snippet SD: Spinner with CustomView

Discussion in 'Code Snippets' started by Star-Dust, May 11, 2017.

  1. Star-Dust

    Star-Dust Expert Licensed User

    I've created a new class with CistomView to have the same features on the spinner object as ListView. A second line of text and the ability to add an image beside each item.

    Also there is the ability to put the screen in gray when you click on the spinner. And finally, the ability to represent each item with rounded edges. In the cases there is an image that will also be rounded.

    Hope it may be useful to you

    Proprietes
    Enabled As Boolean
    SelectedItem As String
    SelectedID As String
    SelectedIndex As String
    GrayDisplay As Boolean ' If Make Screeen gray when click (Set/Get)
    BColor As Int ' BackgroundColor of Spinner's Label (Get/Set)
    TColor As Int ' TextColor of Spinner's Label (Get/Set)
    HintColor As Int ' TextColor of Spinner's Hint (Get/Set)
    RoundCorner As Boolean
    If the spinner opens in an anomalous position:
    Set these prorpietes (left e Top) to set the screen position of the spinner's aperture on the screen.
    For this reason we do not recommend inserting the spinner inside a scrollView because it has problems calculating its opening, or setting the position from code using left and top

    Left As Int
    Top As Int

    Method
    Initialize (vCallback As Object, vEventName As String)
    Add(Text As String, TextHelp As String,ID As String, BackgroundColor As Int, TextColor As Int, Gravities As Int,Image As Bitmap)
    ' Add Single element
    AddAll(L As List, TextHelp As String, BackgroundColor As Int, TextColor As Int, Gravities As Int)
    ' Add a List
    Size as int ' return number of elements
    Clear ' Clear all elements
    RemoveIndex(Position As Int) ' Remove element at Index
    RemoveID(ID As String) ' Remove element from ID
    GetItem(Position As Int) As String ' Get Value from position/index
    GetItemFromID(ID As String) As String ' Get Value from ID
    GetID(Position As Int) As String ' Get ID at position/index
    SetIndex(Position As Int) ' Set selected from position/index
    SetID(Id As String) ' Set selected from ID
    SetBackgroundDrawable(Draw As ColorDrawable) ' Set Background with colordrawable
    SetBackgroundImage(Bitmap As Bitmap) ' Set Background with image
    SetLabelTextSize(TextSizeLabel As Int) ' Set Text Size of label
    Close ' close a ListItem windows
    Open ' Apen a ListItem Windows​

    Event
    ItemClick (Position As Int, Value as String)​

    Update 1.02
    Screen1.png Screen2.png Screen3.png Screen4.png Screen5.png Screen6.png
     

    Attached Files:

    Last edited: Jan 3, 2019
    lazreg, stanks, Maodge and 13 others like this.
  2. Star-Dust

    Star-Dust Expert Licensed User

    Add a Little animation
     
    Gnappos likes this.
  3. MarcoRome

    MarcoRome Expert Licensed User

    Good Job ;).
    Bravo
     
  4. PABLO2013

    PABLO2013 Active Member Licensed User

  5. Filippo

    Filippo Expert Licensed User

    Bravo! but "Non so"

    Bravo! però "Non so" :D
     
    Star-Dust likes this.
  6. luciano deri

    luciano deri Active Member Licensed User

    Come si fa a far comparire il testo dell'item selezionato nello spinner?
     
  7. Star-Dust

    Star-Dust Expert Licensed User

    Non ho capito
    _________________________________________________________
    I do not understand. Please write in English
     
    Last edited: Sep 28, 2017
  8. luciano deri

    luciano deri Active Member Licensed User

    In genere negli spinner, dopo che hai selezionato dalla lista, il contenuto della cella selezionata viene mostrato nello spinner chiuso a sinistra della freccia. Nell'esempio che ho scaricato il riquadro dello spinner rimane sempre vuoto.
     
  9. Star-Dust

    Star-Dust Expert Licensed User

    Ho verificato e non mi da questo errore. In ogni caso nel prossimo Post manderò un aggiornamento della classe, fammi sapere se hai lo stesso problema
    _______________________________________________________________
    I checked and I did not make this mistake. Anyway in the next post I'll send an update to the class, let me know if you have the same problem
     
    Last edited: Sep 28, 2017
  10. Star-Dust

    Star-Dust Expert Licensed User

    Update class
     
    Wolli013 likes this.
  11. Wolli013

    Wolli013 Active Member Licensed User

    Thank You for a verry nice class!
     
    Star-Dust likes this.
  12. magi6162

    magi6162 Well-Known Member Licensed User

    Sorry,
    where do I find the class?
     
  13. Star-Dust

    Star-Dust Expert Licensed User

    I've included an updated version of the class. You can download it directly from the first post
     
    Last edited: Oct 26, 2017
    Erel and Filippo like this.
  14. magi6162

    magi6162 Well-Known Member Licensed User

    thanks ...
     
  15. Johan Hormaza

    Johan Hormaza Active Member Licensed User

    What would be the problem?
    upload_2018-4-20_12-43-16.png
     
  16. Star-Dust

    Star-Dust Expert Licensed User

    I have to see the code, the error says it is not initialized
     
    Johan Hormaza likes this.
  17. Johan Hormaza

    Johan Hormaza Active Member Licensed User

    I already solved the error, what happened was that I was loading it with a Panel.loadlayout, and that did not work. Thanks in advance.
    By the way, this bookstore is great, my brother.
     
  18. Star-Dust

    Star-Dust Expert Licensed User

    Thank's
     
  19. Johan Hormaza

    Johan Hormaza Active Member Licensed User

    I have the Spinner in one position, but the panel that is displayed appears in another position.
    What would be the problem?
    Thank you
     
  20. Star-Dust

    Star-Dust Expert Licensed User

    Sometimes if there are too many nested panels it can not find the absolute position.

    On spinner you will find two porprieties that allow to correct this problem: Spinner.Left and Spinner.Top.

    After you have hooked the Spinner in a panel, Assign Spinner.left and Spinner.Top the position you want it to appear on the screen and everything resolves.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice