Android Question B4XPlusMinus value change in xCustomListView

Hi, I'm having a trouble in my project with B4XPlusMinus. I'm using panel as a cell (card) for xcustomlistview. In my panel I'm using B4XPlusMinus for change item quantity.

This is what it looks like,
Screenshot_20200602_162644_b4a.example.jpg

My problem is I can get specific value from panel (which panel/button I just clicked) by using below code,
B4X: Copy
    Dim index As Int = CLV.GetItemFromView(Sender)
    Dim pnl1 As B4XView = CLV.GetPanel(index)
    Dim pnl2 As B4XView = pnl1.GetView(0)
    'example : Log(pnl2.GetView(6).Text)

But when I use above code for B4XPlusMinus1_ValueChanged (Value As Object) it giving me an error,

java.lang.ClassCastException: b4a.example.b4xplusminus cannot be cast to android.view.View

I want to change B4XPlusMinus value and save that value in SQLite database. I don't know how to get which panel that B4XPlusMinus belongs.

this is the code I've used,
B4X: Copy
Sub B4XPlusMinus1_ValueChanged (Value As Object)
    Dim index As Int = CLV.GetItemFromView(Sender)
    Dim pnl1 As B4XView = CLV.GetPanel(index)
    Dim pnl2 As B4XView = pnl1.GetView(0)
    SQL1.ExecNonQuery($"UPDATE cart(quantity) VALUES (${Value}) WHERE id=${pnl2.GetView(6).Text}"$)
End Sub

And this is the error,
java.lang.ClassCastException: b4a.example.b4xplusminus cannot be cast to android.view.View

I hope you can understand what I'm saying. Sorry about my English language. If anyone know how to fix this, Please let me know.

Thank you
 
Last edited:
Code: Copy
 SQL1.ExecNonQuery($"UPDATE cart(quantity) VALUES (${Value}) WHERE id=${pnl2.GetView(6).Text}"$)
This code is wrong. You should use parameterized queries.

Code: Copy
Sub B4XPlusMinus1_ValueChanged (Value As Object)
    Dim pm As B4XPlusMinus = Sender
    Dim index As Int = CLV.GetItemFromView(pm.mBase)
 
Upvote 0
Back
Top