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

    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

    java.lang.ClassCastException: cannot be cast to android.view.View
        at anywheresoftware.b4a.objects.B4XViewWrapper.asViewWrapper(
        at anywheresoftware.b4a.objects.B4XViewWrapper.getParent(
        at b4a.example3.customlistview._getitemfromview(
        at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(
        at anywheresoftware.b4a.BA.raiseEvent2(
        at anywheresoftware.b4a.BA.raiseEvent(
        at anywheresoftware.b4a.keywords.Common$
        at android.os.Handler.dispatchMessage(
        at android.os.Looper.loop(
        at java.lang.reflect.Method.invoke(Native Method)
    java.lang.ClassCastException: cannot be cast 
    to android.view.View
    when i try to excute this line

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

    Here is the full 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)
    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.
  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