Android Question CustomListView modify

luisro

Member
Licensed User
B4X:
Sub clv1_ItemClick (Index As Int, Value As Object)
 
    Dim pnl As Panel = clv1.GetPanel(Index)
    Dim lbl As Label = pnl.GetView(4)
 
    If G = 0 Then
    Activity.AddView(panel2, 0, 60dip, pnl.Width, pnl.Height)
    G = 1
    End If
 
    panel2.RemoveAllViews
    vartomada = lbl.Text
    pnl.RemoveView
    clv1.AsView.Top = 210dip
 
    If bandera = 0 Then
    clv1.AsView.Height = clv1.AsView.Height - 180dip
    bandera = 1
    End If
 
    pnl.GetView(6).Visible = False
    pnl.getview(5).Visible = False

    panel2.AddView(pnl, 0 , 0, 100%y, 100%x)
    clv1.Clear
    cargarvar
 
End Sub

In my code I take a panel of the CLV and I add it in the top, then I take a value of the label of the selected panel (price of the product) I compare it with all the prices of all the CLV item and if it is higher or lower than the selected one , To make visible a label with the difference between the prices but to add an image (up arrow or down arrow) my code works perfectly, but filling again the CVL with a SQL query.

B4X:
Sub cargarvar
    ProgressDialogHide
    Dim cmd As DBCommand
    cmd.Initialize
    cmd.Name = a
    reqManager.ExecuteQuery(cmd, 0, "select")
End Sub

B4X:
Case "select"
             
                Dim result As DBResult = reqManager.HandleJob(job)
                For Each records() As Object In result.Rows
                    Dim a1,a2,a3,a4,a5,a6,a7 As String
                    Dim buffer() As Byte
                    buffer = records(result.Columns.Get("imagen"))
                    a1 = records(result.Columns.Get("lote"))
                    a2= records(result.Columns.Get("nombre"))
                    a3 = records(result.Columns.Get("gramaje"))
                    a4 = records(result.Columns.Get("precio"))
                    a5 = records(result.Columns.Get("leche"))
                    a6 = records(result.Columns.Get("azucar"))
                    a7 = records(result.Columns.Get("instantaneo"))
                    p.Initialize("")
                    p2.Initialize("")
                    Activity.AddView(p,0,0,100%y,100%x)
                    p.LoadLayout("2")
                    p.RemoveView
                    img.Bitmap = reqManager.BytesToImage(buffer)
                    Label1.Text = a1
                    label2.Text = a2
                    label3.Text = a3&"Gr"
                    label4.Text = a4
                    convert = a4
                    convert = NumberFormat2(a4,0,2,2,True)
                    Label12.Text = convert
  
                    If a5 = 1 Then
                        ck1.Bitmap = bitmap7
                    Else
                        ck1.Bitmap = bitmap8
                    End If
                    '
                    If a6 = 1 Then
                        ck2.Bitmap = bitmap7
                    Else
                        ck2.Bitmap = bitmap8
                    End If
                    '
                    If a7 = 1 Then
                        ck3.Bitmap = bitmap7
                    Else
                        ck3.Bitmap = bitmap8
                    End If


                    If vartomada < a4 Then
                        label5.Text = a4-vartomada
                        label5.Text = NumberFormat2(label5.Text,0,2,2,True)
                    End If

                    If vartomada < a4 Then
                        ImageView2.Bitmap = bitmap4
                    End If

                    If vartomada  > a4 Then
                        label5.Text = vartomada-a4
                        label5.Text = NumberFormat2(label5.Text,0,2,2,True)
                    End If

                    If vartomada  > a4 Then
                        ImageView2.Bitmap = bitmap5
                    End If

                    clv1.Add(p,p.Height,"")
                Next
        End Select

I can not find the way to take the panel, remove it from the CLV, take it to the top, take the value of the label (4), compare the value of the label (4) with all tags (4) of all panels, modify all CLV panels, put visible images or assign it, and if you click again take the top panel add it to CLV in x position, and perform the above procedure. All this in order not to perform the SQL query again and fill the CLV.

Thanks in advance.

Post: In its defect as it is already loaded the CLV to work with him to modify its values in relation to the clicked one
 
Last edited:

luisro

Member
Licensed User
When taking a panel in position (i), the value is taken with pnl.GetView (x) but how do I change that value and add it again in that panel value?
 
Upvote 0

luisro

Member
Licensed User
I try this is more or less what I want, but it generates the following error.

B4X:
Sub car

For i = 0 To clv1.GetSize - 1
    Dim panel1 As Panel = clv1.GetPanel(i)  '// here indicates the error
    Dim lbl As Label = panel1.GetView(2)
    Dim imgp As ImageView = p.GetView(7)
    If vartomada <lbl.Text Then
            lbl.Text = lbl.text-vartomada
            lbl.Text = NumberFormat2(lbl.Text,0,2,2,True)
    End If

    If vartomada < lbl.text Then
        imgp.Bitmap = bitmap4
    End If

    If vartomada  > lbl.text Then
            lbl.Text = vartomada-lbl.text
            lbl.Text = NumberFormat2(lbl.Text,0,2,2,True)
    End If

    If vartomada  > lbl.text Then
        imgp.Bitmap = bitmap5
    End If
Next
End Sub

B4X:
** Service (httputils2service) Start **
Class not found: b4j.example.main$_dbresult, trying: b4a.example.main$_dbresult
Error occurred on line: 375 (productoscategoria)
java.lang.RuntimeException: Object should first be initialized (View).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at anywheresoftware.b4a.samples.customlistview.customlistview._getpanel(customlistview.java:242)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:167)
    at anywheresoftware.b4a.debug.Debug.delegate(Debug.java:259)
    at b4a.example.productoscategoria._car(productoscategoria.java:874)
    at b4a.example.productoscategoria._clv1_itemclick(productoscategoria.java:1026)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:897)
    at anywheresoftware.b4a.keywords.Common.CallSubNew3(Common.java:847)
    at anywheresoftware.b4a.samples.customlistview.customlistview._panel_click(customlistview.java:478)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:179)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:163)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
    at android.view.View.performClick(View.java:4781)
    at android.view.View$PerformClick.run(View.java:19874)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5254)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
 
Last edited:
Upvote 0

luisro

Member
Licensed User
For reasons of time do not manage to solve the following, just the application works only every time there is a clv1 make a query.

Thank you very much Erel better support than here is not there.
 
Upvote 0
Top