Android Tutorial Action List module - Creating a custom view

Discussion in 'Tutorials & Examples' started by Erel, Jan 24, 2012.

  1. alan1968

    alan1968 Active Member Licensed User

    I put my app in beta test on marquet and I have a user that I shared an error Appears when he selects a elelment the list in the procedure "touch" I can not reproduce this has any error on my tablet and smarphone apparently it must be in android 3.0

    the rapport

    "vBeta 1.026 févr. 2012 11:21:401 rapports par semaine
    100%1 rapports
    --------------------------------------------------------------------------------

    java.lang.RuntimeException: MotionEvent { action=ACTION_UP, id[0]=0, x[0]=679.0, y[0]=240.0, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=72384276, downTime=72384088, deviceId=2, source=0x1002 } recycled twice!
    at android.view.MotionEvent.recycle(MotionEvent.java:1673)
    at android.view.ViewRootImpl.finishMotionEvent(ViewRootImpl.java:2904)
    at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:2895)
    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2466)
    at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:845)
    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2475)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)
    "
     

    Attached Files:

    Last edited: Feb 27, 2012
  2. priitp

    priitp Member Licensed User

    Nice module.

    I had an options menu and one user complained that it doesn't show up in Android 4 (HTC One V).
    Thought that it is backward compatibility issue and implemented the ActionList.
    Launcing it as
    Code:
    Sub Activity_KeyPress (KeyCode As Int) As Boolean
    If KeyCode = KeyCodes.KEYCODE_MENU Then
    Still no success.
    Appears there is no Meny key any more (but it still does exsist in Emulator).

    What might be a good way to open this ActionList?

    I have read about three vertical dots somewhere on Action
    and about long keypress on MultiTasking/Recent Applications.

    Thanks
    Priit
     
  3. Erel

    Erel Administrator Staff Member Licensed User

    The menu button should appear unless you set the targetSdkVersion to 11 or above.
     
  4. priitp

    priitp Member Licensed User

    Thanks Erel,

    I made one menu item and clicking on it does open ActionList.
    It works but has one extra step/click.
    Click on three dots -> Click on menu item -> Click on ActionList item

    Could it be possible to capture/process the click on the three verical dots and bypass the extra step?

    Priit
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    You can catch the menu keypress event (see post #22 and return true to consume the event).
     
  6. priitp

    priitp Member Licensed User

    At least in emulator with debuger it doesnt fire keypress when clicking on the three dots.
    Code:
    Sub Activity_KeyPress (KeyCode As Int) As Boolean
    Priit
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    It should work with a real device (I just tested it with Android 4.0 device).
     
  8. priitp

    priitp Member Licensed User

    What KeyCode does it give?
    KeyCodes.KEYCODE_MENU?

    Sorry, can't find it myself.
    Priit
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    Yes.
     
  10. Bernd68

    Bernd68 Member Licensed User

    How to get ActionList without a title

    Hi Erel,

    i've implemented the Al Modul and it works very smooth. but now i would need an ActionList without the title.
    So i've tried the following

    Code:
    al = ActionListModule.InitializeList(150dipNull"Main")
    So no text for the Title is shown, which is correct, but the ActionList still holds "an empty part" for the title.

    May you could update the module, that in case of "No title / Null", the space for the title will be removed.

    Tried myself, but still learn and could not figure it out.

    Regards
    Bernd
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    Please do not post duplicate questions. See my answer in the other thread.
     
  12. Yeshua

    Yeshua Member Licensed User

    item click

    :sign0085:how do I get to perform an action when an item is pressed?

    for example:

    If "item #1" click then Panel1.Visible = True.

    Thanks!
     
  13. Erel

    Erel Administrator Staff Member Licensed User

    You should handle the ActionList_Result event (see the example in the first post).
     
  14. Yeshua

    Yeshua Member Licensed User

    item click

    by Erel, I found the sub but I needed to start the code.:BangHead:
     
  15. Erel

    Erel Administrator Staff Member Licensed User

    Add the items text as the last parameter when you add the items.
     
  16. adalexander

    adalexander Member Licensed User


    What is a bas file and where it goes on, I find it written anywhere but I do not understand, thank you ..
     
  17. Erel

    Erel Administrator Staff Member Licensed User

    A bas file is a module. You add it to your project by clicking on: Project - Add Existing Module.

    Note that this is an old example. There are now better ways to implement such a list.
     
  18. adalexander

    adalexander Member Licensed User

    [Quote = "Erel, palo: 81.206, membro: 1"] Il progetto allegato contiene un modulo di codice che è possibile utilizzare nei vostri progetti per mostrare un elenco personalizzato che l'utente può scegliere tra:

    [​IMG]

    L'elenco viene compilato manualmente. Ciò significa che non dovrebbe essere troppo difficile da personalizzare e migliorare ulteriormente esso.

    Ci sono diverse impostazioni che possono essere modificate in Process_Globals Sub:
    Code:
    Dim ItemHeight Come Int: ItemHeight = 45dip
       
    Dim TextSize Come Float: TextSize = 16 'NON immergere.
       TextLeftPos Dim come INT: TextLeftPos = 40DIP
       
    Dim TextColor Come Int: TextColor = Colors.LightGray
       
    Dim TopPadding Come Int: TopPadding = 5dip
       
    Dim ImageWidth Come Int: ImageWidth = 16DIP
       
    Dim ImageHeight Come Int: ImageHeight = 16DIP
       ImageLeftPos 
    Dim come INT: ImageLeftPos = 10dip
       ImageTopPos 
    Dim come INT: ImageTopPos = (ItemHeight - ImageHeight) / 2
       
    Dim SelectionColor Come Int: SelectionColor = 0xFFFF8000
    [/ Code]

    Lo sfondo è un
    'immagine nove patch. Vedere questo tutorial per ulteriori informazioni su queste immagini: [URL='http://www.basic4ppc.com/forum/showthread.php?p=80908']Nove immagini di patch esercitazione[/URL]

    Il seguente codice mostra come creare e mostrare questo elenco:
    [Code]
    Global 
    Sub
       
    Dim al Come ActionList
    End Sub

    Sub Activity_Create (FirstTime As Boolean)
       
    Activity.LoadLayout ("1")
       al = ActionListModule.InitializeList (
    150dip"Scegli azione""Main")
       ActionListModule.AddActionItem (
    "Articolo # 1" al,, LoadBitmap (File.DirAssets, "bomb.png"), 1)
       ActionListModule.AddActionItem (al, 
    "Item # 2"LoadBitmap (File.DirAssets, "book_add.png"), 2)
       ActionListModule.AddActionItem (
    "# articolo 3" al,, LoadBitmap (File.DirAssets, "book_open.png"), 3)
       ActionListModule.AddActionItem (al, 
    "Item # 4"LoadBitmap (File.DirAssets, "wrench.png"), 4)
       ActionListModule.AddActionItem (
    "# articolo 5" al,, LoadBitmap (File.DirAssets, "wrench_orange.png"), 5)
       ActionListModule.AddActionItem (
    "# articolo 6" al,, Null6)
    End Sub

    Sub ActionList_Touch (Azione Come Int, X come float, Y come Float) come booleano
       
    'I delegati l'evento di tocco al modulo di codice
       ActionListModule.Touch (Sender, Azione, X, Y)
       Ritorno Vero
    End Sub


    Sub Activity_KeyPress (KeyCode Come Int) come booleano
       
    'Premendo il tasto indietro, mentre la lista è visibile chiuderà la lista
       Se KeyCode = KeyCodes.KEYCODE_BACK E al.Visible Poi
          ActionListModule.Hide (al)
          Ritorno Vero
       
    End If
    End Sub
    'Questo sub viene generato quando l'utente preme su un elemento
    'ReturnValue è il valore assegnato alla voce selezionata
    Sub ActionList_Result (ReturnValue As Object)
       
    Log (ReturnValue)
       
    ToastMessageShow ("ReturnValue =" & ReturnValue, True)
    End Sub

    Sub btnShow_Click
       ActionListModule.Show (al, Attività, 
    10dip10dip)
    End Sub
    Sub btnHide_Click
       ActionListModule.Hide (al)  
    End Sub
    [/ Code]
    Nel modulo attività si dovrebbe avere ActionList variabile globale.
    La riga seguente crea un nuovo ActionList e lo assegna alla variabile:
    [Code]
    al = ActionListModule.InitializeList (
    150dip"Scegli azione""Main")
    [/ Code]
    I parametri sono: larghezza, il titolo e il nome del modulo attività (necessaria per generare l
    'evento Risultato).

    L
    'aggiunta di elementi viene fatto chiamando:
    [Code]
    ActionListModule.AddActionItem (
    "# articolo 5" al,, LoadBitmap (File.DirAssets, "wrench_orange.png"), 5)
    [/ Code]
    I parametri sono: variabile ActionList, una nota di testo, immagine articolo (o nullo) e il valore che verrà restituito quando l
    'utente fa clic su questo elemento.

    Questo modulo richiede la libreria 
    Animation (il menu svanisce in e out) e la biblioteca di riflessione (per l'immagine nove patch).

    Come spiegato nel tutorial nove patch, l
    'immagine nove-patch si trova negli oggetti \ res \ drawable e deve essere di sola lettura.

    Il codice è anche un buon esempio per la creazione di una visualizzazione personalizzata con un modulo di codice.

    [B]Credits[/B]
    Immagine di sfondo: [URL=
    'http://android9patch.blogspot.com/']Android 9 cerotto[/URL]
    Icone Esempio: [URL='http://famfamfam.com/lab/icons/silk/']famfamfam.com: Silk Icons[/URL] [/ quote]
    [Quote = "Erel, palo: 81.206, membro: 1"] Il progetto allegato contiene un modulo di codice che è possibile utilizzare nei vostri progetti per mostrare un elenco personalizzato che l'utente può scegliere tra:

    [IMG]http://www.basic4ppc.com/basic4android/images/SS-
    2012-01-24_12.20.48.png[/IMG]

    L
    'elenco viene compilato manualmente. Ciò significa che non dovrebbe essere troppo difficile da personalizzare e migliorare ulteriormente esso.

    Ci sono diverse impostazioni che possono essere modificate 
    in Process_Globals Sub:
    [Code]
       
    Dim ItemHeight Come Int: ItemHeight = 45dip
       
    Dim TextSize Come Float: TextSize = 16 'NON immergere.
       TextLeftPos Dim come INT: TextLeftPos = 40DIP
       
    Dim TextColor Come Int: TextColor = Colors.LightGray
       
    Dim TopPadding Come Int: TopPadding = 5dip
       
    Dim ImageWidth Come Int: ImageWidth = 16DIP
       
    Dim ImageHeight Come Int: ImageHeight = 16DIP
       ImageLeftPos 
    Dim come INT: ImageLeftPos = 10dip
       ImageTopPos 
    Dim come INT: ImageTopPos = (ItemHeight - ImageHeight) / 2
       
    Dim SelectionColor Come Int: SelectionColor = 0xFFFF8000
    [/ Code]

    Lo sfondo è un
    'immagine nove patch. Vedere questo tutorial per ulteriori informazioni su queste immagini: [URL='http://www.basic4ppc.com/forum/showthread.php?p=80908']Nove immagini di patch esercitazione[/URL]

    Il seguente codice mostra come creare e mostrare questo elenco:
    [Code]
    Global 
    Sub
       
    Dim al Come ActionList
    End Sub

    Sub Activity_Create (FirstTime As Boolean)
       
    Activity.LoadLayout ("1")
       al = ActionListModule.InitializeList (
    150dip"Scegli azione""Main")
       ActionListModule.AddActionItem (
    "Articolo # 1" al,, LoadBitmap (File.DirAssets, "bomb.png"), 1)
       ActionListModule.AddActionItem (al, 
    "Item # 2"LoadBitmap (File.DirAssets, "book_add.png"), 2)
       ActionListModule.AddActionItem (
    "# articolo 3" al,, LoadBitmap (File.DirAssets, "book_open.png"), 3)
       ActionListModule.AddActionItem (al, 
    "Item # 4"LoadBitmap (File.DirAssets, "wrench.png"), 4)
       ActionListModule.AddActionItem (
    "# articolo 5" al,, LoadBitmap (File.DirAssets, "wrench_orange.png"), 5)
       ActionListModule.AddActionItem (
    "# articolo 6" al,, Null6)
    End Sub

    Sub ActionList_Touch (Azione Come Int, X come float, Y come Float) come booleano
       
    'I delegati l'evento di tocco al modulo di codice
       ActionListModule.Touch (Sender, Azione, X, Y)
       Ritorno Vero
    End Sub


    Sub Activity_KeyPress (KeyCode Come Int) come booleano
       
    'Premendo il tasto indietro, mentre la lista è visibile chiuderà la lista
       Se KeyCode = KeyCodes.KEYCODE_BACK E al.Visible Poi
          ActionListModule.Hide (al)
          Ritorno Vero
       
    End If
    End Sub
    'Questo sub viene generato quando l'utente preme su un elemento
    'ReturnValue è il valore assegnato alla voce selezionata
    Sub ActionList_Result (ReturnValue As Object)
       
    Log (ReturnValue)
       
    ToastMessageShow ("ReturnValue =" & ReturnValue, True)
    End Sub

    Sub btnShow_Click
       ActionListModule.Show (al, Attività, 
    10dip10dip)
    End Sub
    Sub btnHide_Click
       ActionListModule.Hide (al)  
    End Sub
    [/ Code]
    Nel modulo attività si dovrebbe avere ActionList variabile globale.
    La riga seguente crea un nuovo ActionList e lo assegna alla variabile:
    [Code]
    al = ActionListModule.InitializeList (
    150dip"Scegli azione""Main")
    [/ Code]
    I parametri sono: larghezza, il titolo e il nome del modulo attività (necessaria per generare l
    'evento Risultato).

    L
    'aggiunta di elementi viene fatto chiamando:
    [Code]
    ActionListModule.AddActionItem (
    "# articolo 5" al,, LoadBitmap (File.DirAssets, "wrench_orange.png"), 5)
    [/ Code]
    I parametri sono: variabile ActionList, una nota di testo, immagine articolo (o nullo) e il valore che verrà restituito quando l
    'utente fa clic su questo elemento.

    Questo modulo richiede la libreria 
    Animation (il menu svanisce in e out) e la biblioteca di riflessione (per l'immagine nove patch).

    Come spiegato nel tutorial nove patch, l
    'immagine nove-patch si trova negli oggetti \ res \ drawable e deve essere di sola lettura.

    Il codice è anche un buon esempio per la creazione di una visualizzazione personalizzata con un modulo di codice.

    [B]Credits[/B]
    Immagine di sfondo: [URL=
    'http://android9patch.blogspot.com/']Android 9 cerotto[/URL]
    Icone Esempio: [URL='http://famfamfam.com/lab/icons/silk/']famfamfam.com: Silk Icons[/URL] [/ quote]

    hello erel a question, 
    and I would like to anda twolines listview bitmap, I've seen several guides but all incomprehensible, I do not understand the steps, considering that I'm learning from you, but I already have something long is the road had often find guides for people who are already advanced do not go well for me, how can I do to create this list? I am reading other guides also visual basic, but this language is a bit different, but there is not a guide to understand this language? thanks for everything ..
     
  19. jamezy92

    jamezy92 Banned

    how would i make the full container (view) move down from the top 100 pixels?
     
  20. Erel

    Erel Administrator Staff Member Licensed User

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