Android Question Click item and checkbox in a customlisview and update database

asales

Well-Known Member
Licensed User
Click item and checkbox in a customlisview and update database

I used the code of this post:
http://www.basic4ppc.com/android/forum/threads/customlistview-and-database.30541/#post-177587
to execute an SQL that returns several fields and populate a customlistview with a few fields of this SQL and is OK.

I have two questions:

1 - I put a checkbox in the customlistview, related with a boolean field in database.
How I can click in this checkbox and update the boolean field in database?

2 - How I can click in a item of customlistview and show all fields of selected item in a messagebox?
I try to make this, but not works (Logs shows: "No records found. (Map) Not initialized"):
B4X:
Sub clv1_ItemClick (index As Int, Value As Object)
    Dim m As Map
    m = DBUtils.ExecuteMap(Main.SQL1, "SELECT id, project, author, marked FROM myTable WHERE id = ?", Array As String(Value))
    Dim myText As String
    myText = m.Get("project") & CRLF & m.Get("author")
    Msgbox(myText, "")  
End Sub

Where I going wrong?

Thanks in advance.
 

Erel

Administrator
Staff member
Licensed User
1. Again, you need to check the example that comes with CustomListView.
This is the relevant code to handle the checkbox. It is not so simple but go over it and you will understand it:
B4X:
Sub chk_CheckedChange(Checked As Boolean)
   Dim index As Int
   index = clv3.GetItemFromView(Sender)
   Dim pnl As Panel
   pnl = clv3.GetPanel(index)
   Dim chk As CheckBox
   chk = pnl.GetView(2)
   Msgbox("Item value: " & clv3.GetValue(index) & CRLF & "Check value: " & chk.Checked, "")
End Sub

2. Add Log(Value). Is this the value that you are looking for?
 
Upvote 0

asales

Well-Known Member
Licensed User
1. Again, you need to check the example that comes with CustomListView.
This is the relevant code to handle the checkbox. It is not so simple but go over it and you will understand it:
B4X:
Sub chk_CheckedChange(Checked As Boolean)
   Dim index As Int
   index = clv3.GetItemFromView(Sender)
   Dim pnl As Panel
   pnl = clv3.GetPanel(index)
   Dim chk As CheckBox
   chk = pnl.GetView(2)
   Msgbox("Item value: " & clv3.GetValue(index) & CRLF & "Check value: " & chk.Checked, "")
End Sub
I have seen and used this example, but how I get the record in database and update it, using this information (click on item of customlistview and find the record in database)?

2. Add Log(Value). Is this the value that you are looking for?
Log(Value) shows: "[Ljava.lang.String;@405cd8b0".
I don't know how I can get the id in database using this information.

Thanks for any tip.
 
Upvote 0

asales

Well-Known Member
Licensed User
You are adding an array as the value object.

Where is the code that adds the items?

I used this code:

B4X:
Dim table As List
table = DBUtils.ExecuteMemoryTable(SQL1, "SELECT id, project, author FROM " & myTable,Null,0)

Dim i As Int : i = 0
For Each cols() As String In table
   i = i + 1
   clv1.Add(CreatePanelItem(i & ". " & cols(0), cols(1), cols(2), 100%x, 100%y), 100dip, cols)
Next

based in this post:
http://www.basic4ppc.com/android/forum/threads/customlistview-and-database.30541/#post-177587
 
Upvote 0
Top