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

mangojack

Well-Known 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
 

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)
 

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 ?
 
Top