Android Question Listview help!

Beja

Expert
Licensed User
Longtime User
Hi All,
I am working on a small project and facing difficulty compiling a string array from the contents of the listview.
please help!
Please see that attached screenshot of the user interface.. I want the result be as following:
"4","Soda"
"3","water"
"14","Bottle Soda"
"4","Charcoal"
"6","Ice"
"8","Hotdog"

Only the checked lines are added to the array.. On the other side I will parse the csv file into a SQLite table.
Thanks in advance.
 

Attachments

  • sshot.png
    sshot.png
    38.3 KB · Views: 167

mangojack

Expert
Licensed User
Longtime User
Beja .. just to confirm , you only want the checked items to be eventually written to SQlite db ?
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Yes mangojack,
When the "send" button is clicked, then the UI number in the top edittext box, the spinner value and the button text are put together.. sorry in the csv
example I didn't include the UI number. All unchecked lines will not be included.
Thanks in advance for the help
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
important note:
Not SQLite, but csv file as the csv list above. then send the csv as string array through serial (Bluetooth) to where
I will parse it to SQLite or MS Access.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
That is not a simple ListView. You should specify what view is it.

Also you should post your attempt to create the array and we could look for any errors.
Otherwise we would have to develop your code.

The indication is obvious: cycling on the items of that view, taking only those checked and then create a text file or directly update the db.
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Sorry Luca, it is the customlistview.
I will try to post the code that my old gray cells can come up with !
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
This is the pseudo code until I put it together:
dim stringarray() as string
for x = 0 to list count minus 1
if item(x). checked = true then
stringarray(x) = "spinner(x)" & "," & button1(x).text & crlf
next.
Send stringarray by way of serial port.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
You should use a List, not an array, because you can't resize an array dinamically.
I don't know CustomListView (I prefer CheckedList).
If you can get the views in each item, as you wrote, you should write something like:
Dim lstSelected As List
lstSelected.Initialize

for x (or for Each, if it is possible with CustomListView)
' code to get the spinner and the button
lstSelected.Add(spinner.value & "," & button.text)

File.WriteList(Dir, FileName, lstSelected)



(Now I see how CustomListView works :))
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Beja .. this will give you an idea... and there could be a more efficient way ..

1. in the CustomListView Class Globals change Panels As List from Private to Public.
2 this presumes your CLV is clv3 and your item text are buttons.

B4X:
Sub btnSend_Click
 
   Dim  CheckedItems As List
   CheckedItems.Initialize

   For i = 0 To clv3.panels.Size - 1
     Dim pnl As Panel
     pnl = clv3.GetPanel(i)
     Dim chk As CheckBox
     chk = pnl.GetView(2)
     If chk.Checked = True Then
       Dim  btn As Button
       btn = pnl.GetView(1)
       CheckedItems.Add(btn.Text)  ' add button text to the list / csv file
     End If
   Next
 
   For i = 0 To CheckedItems.Size -1
     Log (CheckedItems.Get(i))
   Next
 
End Sub
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Thanks Luka.. I think that should work, and forget about how customlistview works :)
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Hi mangojack,
Will try your solution and it is specific to the original project, so I think it should work.
Thank you very much.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I advise you to use CheckedList; it will automatically returns a list of selected items.

However, the CustomListView has a function GetPanel that returns a panel according to an index. GetSize returns the number of items (I think).

then

For i = 0 to MyCustomListView.GetSize - 1
private pnl as Panel = MyCustomListView.GetPanel (i)
private btn ...
private spinner ...
etc.
next
 
Upvote 0

mangojack

Expert
Licensed User
Longtime User
Beja .. Lucas is correct , there is no need to change Class Globals "Panels as List" to Public. My Mistake !

Just call clv3.GetSize ...
B4X:
Sub btnSend_Click

  Dim  CheckedItems As List
   CheckedItems.Initialize

   For i = 0 To clv3.GetSize - 1
'............and so on
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I think that a good solution in these cases could be:

Create a type (or better a class) for the "item"
(like: Type tDrinkItem(Qty As Int, Name As String))

Create a routine to build the CustomListView item

Create a routine to get the CustomListView Item content
(like - can contain errors, i'm writing here!
B4X:
Private Sub GetDrinkItemContent(Item As Panel) As tDrinkItem
        Private Result As tDrinkItem : tDrinkItem.Initialize

        Private spnQty As Spinner
        Private chkSelected as CheckBox
        Private btnName as Button
        ' ...
        For Each V As View In Item
              if V is Spinner then ' you could have more than one Spinner, so you should use its Tag property to to distinguish them
                    spnQty = V
                    Result.Qty = spnQty.Value
              else if V is CheckBox then
                    chkSelected = V
              Else IF V is Button then ' you could have more than one Button, so you should...                    btnName = V
                    Result.Name = btnName.Text
              ' ...
              End If
          Next
          Return Result
  End Sub


Then, iterate on CustomListView items
get the item panel (CurrentItem)
private Drink as tDrinkItem = GetDrinkItemContent(CurrentItem)
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
Luka,
I am sure Erel, guarantees and respects your freedom of thought on this forum :)
 
Upvote 0

Beja

Expert
Licensed User
Longtime User
He obviously has a lot of patience
Absolutely!
Many times I ask (not so smart) questions! besides I noticed and tracked his attitude and way of answering all kind of questions, including the off-point, on-point, off-topic, wrong forum... etc.. and I also learn from this, not only from the answers. he is very tolerant.
 
Upvote 0
Top