Android Question Get / Set Label Text from Expandable xCustomListView

A Z M JANNAT UL KARIM

Member
Licensed User
Hi, I am trying to create a Point of Sales application. I am adding an Expandable xCustomListView in my Product Cart area where user's desired product will be showed. When user click on expand button, there will be three button. One is increase product, another one is decrease product and other is remove product. I am successfully manage to create the layout with sample products and quantity but what I am unable to work is with functionality ... means clicking on button will increase quantity label up or down or remove the entire panel.

Following is my code snipes .... When creating Layout ...

B4X:
Sub CreateItem(clr As Int, LineNo As Int, Title As String, ExpandedHeight As Int) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, lstProdCart.AsView.Width, ExpandedHeight)
    p.LoadLayout("CartList")
    p.SetLayoutAnimated(0, 0, 0, p.Width, p.GetView(0).Height) 'resize it to the collapsed height
    
    ' Cart Width Is 30%, So All Width Based On It ...
    pnlProdList.Width = 30%x
    pnlProdDet.Width = 30%x
    ' Can't Manage To Set Width Of The Panels. So Reduce It To 30% Calculation
    lblRowNo.Width = 4%x
    lblProdName.Width = 12%x
    lblQnty.Width = 5%x
    lblWght.Width = 4%x
    lblDropArrow.Width = 5%x
    
    lblLess.Left = 30dip
    lblAdd.Left = lblLess.Width + 30dip
    lblDelete.Left = lblLess.Width + lblAdd.Width + 30dip
    
    lblRowNo.Left = 0
    lblProdName.Left = lblRowNo.Width
    lblQnty.Left = lblRowNo.Width+lblProdName.Width
    lblWght.Left = lblRowNo.Width+lblProdName.Width+lblQnty.Width
    lblDropArrow.Left = lblRowNo.Width+lblProdName.Width+lblQnty.Width+lblWght.Width
    
    lblRowNo.Text = LineNo
    lblProdName.Text = Title
    lblQnty.Text = LineNo
    lblWght.Text = "Pcs"
    pnlProdList.Color = clr
    pnlProdDet.Color = ShadeColor(clr)
    Return p
End Sub

Now I want to create the functionality for Add / Less quantity or Delete ... I had tried it as follows but unable to do it as it shows error ...

B4X:
Sub lblAdd_Click
'    Dim LabelValue As Int = lblQnty.Text
'    LabelValue = LabelValue + 1
'    lblQnty.Text = LabelValue

    Dim index As Int = lstProdCart.GetItemFromView(Sender)
    Log($"Index Of Item ${index}"$)
    Dim pnl As B4XView = lstProdCart.GetPanel(index)
    Dim intProdQnty As B4XView = pnl.GetView(2) ' Third label is Quantity
    Log(intProdQnty) ' Error shows ....
    ' Code to increase the Label text, but how to ...
End Sub

Thank you for your support :)
 

A Z M JANNAT UL KARIM

Member
Licensed User
This is what it looks like ..

1jdtt_Zal7Y2giivZQ7pn5VWXSLrum3veNsr5vgiE84xxzwOPMOSV4iz9AJDFLz-kbr1r8QwbONRpuY6IkYce0lKI82bh22zvLQvwmTjfFMxw35HPg7w2Aed018wU0KCM9zjWVdBDDwg9UzGFZ58MQ2sv3pWKJvRbmi1HBRiuG5V-R9RlJSLrh8_8GE1xy3iJKIVgrvMykaXrSGT7uYOGUMBQqY2OeA-w3gikPMrsLukLfySZAsL_R9J-5PHJBkMphilnO8_VnWYdky9clPnIldwwi4851bYrUIDzuZLslPN8jF_Ft8X3MfUw9gRJSguOyE-lIydVjIB2sYIjZttS7M--wUcMsocy5yVbVpQWH8WXfEEqcyjowcxS4jhTKe9z0Oi7vyRbfwRrYaoxprkxn3YjSjJDp1AtvIxogOq6DC8_-MJY4-uQskNHEAngVBFZkw2IX-aRYEIu3vvFPgTCmEB4unH8RXwBTPHTwIpHaJ3vgl2lxHQeQ2IvFRfuOdjifawTqwiyyjL52QoTAFIduiJ_NWYh5HJfU3JNqmxstbjLmyc0QEM6SsoVP_P4nq5DNt9KcPGP-diqQZIsPvhS3FYRZbrA6IPn5EPKvlVT3ylh-n3Pw5IZHt91tnd3Y_mvpLr5LnKolNlm-CUwBGDWqHxxOuZUZfI=w834-h625-no
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
try ...

B4X:
Sub lblAdd_Click
    Dim index As Int = lstProdCart.GetItemFromView(Sender)
    Log($"Index Of Item ${index}"$)
    Dim pnl As B4XView = lstProdCart.GetPanel(index)
    pnl.GetView(2).Text =  NumberFormat(pnl.GetView(2).text +1, 1, 0)
End Sub
 
Upvote 0

A Z M JANNAT UL KARIM

Member
Licensed User
try ...

B4X:
Sub lblAdd_Click
    Dim index As Int = lstProdCart.GetItemFromView(Sender)
    Log($"Index Of Item ${index}"$)
    Dim pnl As B4XView = lstProdCart.GetPanel(index)
    pnl.GetView(2).Text =  NumberFormat(pnl.GetView(2).text +1, 1, 0)
End Sub

Following error shows while clicking on Add Label

B4X:
Logger connected to:  HUAWEI BGO-DL09
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (orders) Create, isFirst = true **
** Activity (orders) Resume **
Index Of Item 2
Error occurred on line: 176 (Orders)
java.lang.RuntimeException: Object should first be initialized (View).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.objects.B4XViewWrapper.GetView(B4XViewWrapper.java:298)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:180)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:5264)
    at android.view.View$PerformClick.run(View.java:21297)
    at android.os.Handler.handleCallback(Handler.java:743)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:150)
    at android.app.ActivityThread.main(ActivityThread.java:5578)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
 
Upvote 0

A Z M JANNAT UL KARIM

Member
Licensed User
I think I had managed to sort out the issue. Following are the codes ...

B4X:
    Dim index As Int = lstProdCart.GetItemFromView(Sender)
    Log($"Index Of Item ${index}"$)
    Dim pnl As B4XView = lstProdCart.GetPanel(index)
    Dim lbl As B4XView = pnl.GetView(0) ' First Panel With All Labels
    Dim scndPanel As B4XView = pnl.GetView(1) ' Second Panel With Functional Add / Update / Delete Labels
    lbl.GetView(2).Text = NumberFormat(lbl.GetView(2).text +1, 1, 0)
    Log(lbl.GetView(1).Text)

Thank you MangoJack. How can I delete the Entire Row here ?
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
You should be able to just call .. lstProdCart.RemoveAt(index)
 
Upvote 0
Top