Android Question Get text from Xcustomlistview - SQLite Database

Salinda001

New Member
I created a Xcustom list view as shown in this thread,


to get data i used SQLite database.

To load the layout I used the following code as shown in the above thread,

B4X:
Sub Process_Globals
    Private xui as XUI
    Type itemvalue ( lblcode As Label, lblstyle As Label, lblgsm As Label ,btnedit As Button, btndelete As Button)

End Sub

Private Sub CreateItem (Code As String, GSM As String, Style As String, iv As itemvalue) As B4XView
    Dim p As Panel = xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0,100%x, 215dip)
    iv.Initialize
    iv.lblcode = lblccode
    iv.lblgsm = lblgsm
    iv.lblstyle = lblstyle
    iv.btndelete = btndelete
    iv.btnedit = btnedit
    p.LoadLayout("Items")
    lblcode.text = FabricCode
    lblgsmt.Text = GSM
    lblstyle.Text = Style
    Return p
End Sub

Sub ShowDB
    CustomListView1.Clear
    Dim iv As itemvalue
    Connection.myCUR = Connection.mySQL.ExecQuery("SELECT * from Customer")
    If Connection.myCUR.RowCount > 0 Then
        For i = 0 To Connection.myCUR.RowCount - 1
            Connection.myCUR.Position = i
            CustomListView1.Add(CreateItem(Connection.myCUR.GetString("Code"),Connection.myCUR.GetString("GSM"),Connection.myCUR.GetString("Style"),iv),iv)
        Next
   End If
End Sub

This all works fine... but,

Now what I want is when click the Edit button, I want to get the text from iv.lblstyle.text

Here is the Code I used,

B4X:
Sub btnedit_Click
    Status = "U"
    Dim index As Int = CustomListView1.GetItemFromView(Sender)
    Dim iv As itemvalue = CustomListView1.GetValue(index)
    Dim Value As String
    Value = iv.lblstyle.text

    Connection.myCUR = Connection.mySQL.ExecQuery("SELECT * from Customer WHERE Style='" & Value & "'")
      
    If Connection.myCUR.RowCount > 0 Then
        For i = 0 To Connection.myCUR.RowCount - 1
            Connection.myCUR.Position = i
            c =  Connection.myCUR.GetString("Code")
            st =  Connection.myCUR.GetString("Style")
            gsm =  Connection.myCUR.GetString("GSM")
        Next
    End If
End Sub

then I get an error to initialize the label (iv.lblstyle.text)

How to get the text ? :-(
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Connection.myCUR = Connection.mySQL.ExecQuery("SELECT * from Customer WHERE Style='" & Value & "'")
This code is really bad. Watch the SQL video tutorial: https://www.b4x.com/etp.html?vimeography_gallery=1&vimeography_video=263187269

You should also use ResultSet instead of Cursor and you should close it when done.

You should load the layout before you assign the views variables. However it will be better to store the text in ItemValue instead of the label. This will be useful when you want to switch to lazy loading.
 
Upvote 0
Top