Android Question CLV Index and msgbox

Discussion in 'Android Questions' started by Sasuke Sama, Jun 19, 2019.

  1. Sasuke Sama

    Sasuke Sama Active Member Licensed User

    Hi
    I have a msgbox that when the user chose Yes the app gets the current clv index from a label click and then do other stuff but im getting this error

    Code:
    java.lang.ClassCastException: android.app.AlertDialog cannot be cast to android.view.View
        at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(B4XViewWrapper.java:
    68)
        at anywheresoftware.b4a.objects.B4XViewWrapper.getParent(B4XViewWrapper.java:
    165)
        at b4a.example3.customlistview._getitemfromview(customlistview.java:
    408)
        at seven.zero.nvp.main$ResumableSub_delete_Click.resume(main.java:
    976)
        at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:
    245)
        at anywheresoftware.b4a.BA.raiseEvent2(BA.java:
    185)
        at anywheresoftware.b4a.BA.raiseEvent(BA.java:
    171)
        at anywheresoftware.b4a.keywords.Common$
    1.onClick(Common.java:481)
        at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:
    172)
        at android.os.Handler.dispatchMessage(Handler.java:
    106)
        at android.os.Looper.loop(Looper.java:
    201)
        at android.app.ActivityThread.main(ActivityThread.java:
    6806)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:
    547)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:
    873)
    java.lang.ClassCastException: android.app.AlertDialog cannot be cast 
    to android.view.View
    when i try to excute this line

    Code:
    Dim index As Int = CLV1.GetItemFromView(Sender)
    It work fine without the msgbox

    Here is the full code

    Code:
    Dim xui As XUI


        
    Dim sf As Object = xui.Msgbox2Async("Delete file?""""Yes""""No"Null)
        
    Wait For (sf) Msgbox_Result (Result As Int)
        
    If Result = xui.DialogResponse_Positive Then
                
    Dim index As Int = CLV1.GetItemFromView(Sender)
    Log(Index)
    End If
     
  2. LucaMs

    LucaMs Expert Licensed User

    It happens because the Sender is the xui.Msgbox2Async, cannot be a View from your CLV (that way).
     
  3. Sasuke Sama

    Sasuke Sama Active Member Licensed User

    its not xui related as it gives the same error with normal msgbox
     
  4. DonManfred

    DonManfred Expert Licensed User

    Help us helping you. Upload a small project which shows the issue
     
  5. LucaMs

    LucaMs Expert Licensed User

    The Sender is the "object" (almost always a View) that has fired the event, so to get the item "from Sender", you have to Click, Touch or other on a View which is part of the item. You are instead waiting for an event fired by a MsgBox (xui or not), so the Sender is part of this one.
     
  6. Sasuke Sama

    Sasuke Sama Active Member Licensed User

    The project is currently empty and the code i posted is the only code in it at the current stage of the project
     
  7. Sasuke Sama

    Sasuke Sama Active Member Licensed User

    So ...
    How can i get the current clv index with a msgbox? Any samples perhaps?
     
  8. LucaMs

    LucaMs Expert Licensed User

    Given your code in post # 1, I suppose your CLV shows a list of files and you want to give the user the option to delete a (selected) file.
    So you should show your msgbox (async) inside the CLV1_ItemClick(Index As Int, Value As Object) event, which returns the Index of the Item clicked and also the Value you associated to that Item. Or in the Click event of the clicked View, like: Sub lblFileName_Click, and here you can useCLV1.GetItemFromView(Sender).
     
    José J. Aguilar likes this.
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