Android Question [SOLVED]xCustomListView problem ?

nanjidusan

Member
Licensed User
I try to use xCustomListView to show the data from database . So I have to use CLV.clear to update query results , unfortunately , CLV.clear will destroy something initilized in Activity_Create . The related data will not be shown when I use CLV_ItemClick . I don't know what the problem is , maybe I missed something .
This is my code :
B4X:
Sub Activity_Create(firstTime As Boolean)
    pnlPage1.Initialize("pnlPage1")
    Activity.AddView(pnlPage1,10dip,10dip,100%x,PanelHeight)
    pnlPage1.LoadLayout("cidian")
    p_initialize
End Sub

Sub p_initialize
    p.Initialize("Panel")
    pnlPage1.AddView(p,0,et.Height,pnlPage1.Width,pnlPage1.Height-et.Height)
    xml.LoadXmlLayout(p, "layout1")
    spl=xml.GetView("label1")
    spl.RemoveView
    p.AddView(spl,5dip,10dip,100%x,10%y)
    spl.TextColor=Colors.Black
    spl.TextSize=22
    sounds.Initialize(1)
    p.Visible=False
    p2.Initialize("")
    p.AddView(p2,-4dip,10%y,100%x,10%y)
    p2.LoadLayout("sound")
    Button3.Text=Chr(0xF028)
    mng=xml.GetView("label2")
    mng.RemoveView
    p.AddView(mng,5dip,20%y,92%x,p.Height-20%y)
    mng.TextColor=Colors.Black
    mng.TextSize=22
End Sub

Sub et_TextChanged (Old As String, New As String)
    Log($"EditText=${et.Text}"$)
    select_str=et.Text.Trim.ToLowerCase
    If select_str<>"" Then
        Button2.Visible=True
    Else
        Button2.Visible=False
    End If
    If SContainEnChar(select_str) Then
        CLV.Clear
        strSQL ="select spelling,concise_meaning,meaning from " & DBTableName & " where spelling like '" & select_str & "%'"
        curData=SQL1.ExecQuery(strSQL)
        For i=0 To curData.RowCount-1
            curData.Position=i
            Private spell As String=curData.GetString("spelling")
            Private mean As String = curData.GetString("meaning")
            CLV.Add(CreateListItem(spell,mean,CLV.AsView.Width,50dip),spell)
        Next
    Else If select_str="" Then
            CLV.Clear
    End If
End Sub

Sub CLV_ItemClick (Index As Int, Value As Object)
    ime.HideKeyboard
    CallSubDelayed2(Me,"Item_show",Value)
End Sub

B4X:
Sub Item_show(s As String)
    CLV.AsView.Visible=False
    p.Visible=True
    strSQL ="select meaning,pronunciation from " & DBTableName & " where spelling = '" & s & "'"
    curData=SQL1.ExecQuery(strSQL)
    curData.Position=0
    spl.Text=s
    mng.Text=(curData.GetString("meaning"))
    Dim pronunciation As String=curData.GetString("pronunciation")
    If pronunciation = Null Then
        Button3.Visible=False
    Else
        Button3.Visible=True
        bounceId = sounds.Load(File.DirAssets,pronunciation )
    End If
End Sub
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
There are many mistakes in this code:

1. Don't use XML layouts.

Activity.AddView(pnlPage1,10dip,10dip,100%x,PanelHeight)
2. Strange code. The panel will extend out of the activity. Use the designer instead.

3. You are not closing the cursor.

4. You should use parameterized queries.

5. I recommend you to use SearchView or B4XTable.

What exactly happens after you clear the items and add new ones?
 
Upvote 0

nanjidusan

Member
Licensed User
There are many mistakes in this code:

1. Don't use XML layouts.


2. Strange code. The panel will extend out of the activity. Use the designer instead.

3. You are not closing the cursor.

4. You should use parameterized queries.

5. I recommend you to use SearchView or B4XTable.

What exactly happens after you clear the items and add new ones?
Thank you . I want to use CLV_ItemClick event to pass value to the sub Item_show , which can open a panel . But the panel will never be shown . I think that it was destroyed by CLV.Clear before .
 
Upvote 0

nanjidusan

Member
Licensed User
There is no problem with clearing the CLV items and adding new ones. Calling CLV.Clear will remove all existing CLV items.
app.GIF


I don't know how to let you know what I mean. But that's the picture. My English is very poor.
If I try to use listview, the same code will work well . But the function of listview is too little .
Do I need to upload my project ?
 
Last edited:
Upvote 0

nanjidusan

Member
Licensed User
I made a stupid mistake. I use a global variable of the same name between sub CreateListItem and sub p_initialize . Then the disaster happened, leading to the destruction of CLV. clear. Thanks , Erel , it's not the xcustomlistview problem .
 
Upvote 0
Top