Android Question CLV Index and msgbox

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

B4X:
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

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

Here is the full code

B4X:
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
 

LucaMs

Expert
Licensed User
its not xui related as it gives the same error with normal msgbox
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.
 

Sasuke Sama

Active Member
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.
So ...
How can i get the current clv index with a msgbox? Any samples perhaps?
 

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).
 
Top