Android Code Snippet [B4X] Create CustomListView items

Tired of repeating the same code over and over again, especially when developing a sample project for other members, I thought I'd create this snippet. It's imperfect, but it's still useful.

B4X, then for B4A, B4J, B4i.

Update
:
I implemented @PaulMeuris's suggestions (post #5), they're good.

I need to read (reread) the tutorial about Snippets, because I can't set the focus on the lblItem to allow editing of that "field." Maybe it's not possible, maybe it can be done on a single field (CustomListView1 in this case).


B4J_JVxMtmWYe0.gif
 

Attachments

  • b4x_CLV_CreateItem.zip
    505 bytes · Views: 3
Last edited:

aeric

Expert
Licensed User
Longtime User
Here is my version:
 

LucaMs

Expert
Licensed User
Longtime User
Here is my version:
I had already seen that one (I searched before writing this one) but it is a bit too specific (it requires the existence of 4 views) and it is convenient to also have a Sub FillCLV.
 

aeric

Expert
Licensed User
Longtime User
I had already seen that one (I searched before writing this one) but it is a bit too specific (it requires the existence of 4 views) and it is convenient to also have a Sub FillCLV.
Of course, as the name Custom, it means it is for a specific use.
I just share an example and anyone can use it as a base.
Remove, add more views and customize further.
There is no 1 size fits all.

This code snippet just reminds me that I also have a similar example.
Please don't misunderstand I don't mean to stop anyone to use other version. I just provide more options.
I believe you share the same intention.
 

PaulMeuris

Well-Known Member
Licensed User
A few additions that might complete the script:
- the first line in the FillCLV subroutine:
B4X:
CustomListView1.Clear
Just to make sure the CLV is empty before filling it up.

- the declaration and initialization of the item panel can be done in 1 line:
B4X:
Dim pnlItem As B4XView = xui.CreatePanel("")

- you could also provide an item click subroutine as it will probably be used:
B4X:
Private Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    ' item clicked
End Sub
 

PaulMeuris

Well-Known Member
Licensed User
You can use many placeholders as in this (modified) example from Erel:
'Iterate over keys and values
dim $map$ as map
For Each $key$ As Object In $map$.Keys
Dim value As Object = $map$.Get($key$)
Next
$end$
You can use the TAB key to go to each variable name to type the correct name.
When you press ENTER you accept the changes and the cursor will be at the location of the $end$ variable from the snippet (if specified).
 

LucaMs

Expert
Licensed User
Longtime User
You can use many placeholders as in this (modified) example from Erel:

You can use the TAB key to go to each variable name to type the correct name.
When you press ENTER you accept the changes and the cursor will be at the location of the $end$ variable from the snippet (if specified).
And indeed I did it that way, but evidently I made a mistake while "executing" it. I'll try again and let you know.
 

LucaMs

Expert
Licensed User
Longtime User
And indeed I did it that way, but evidently I made a mistake while "executing" it. I'll try again and let you know.
Yes, I was "just" typing incorrectly.

It seemed to me that pressing Tab on the first placeholder, the CustomListView name here, didn't change it, so I pressed "Enter" and then the cursor didn't move to the second placeholder.

Instead, pressing Tab is enough and Enter should only be pressed at the end of filling out.

B4J_nWtkVFMjkX.gif


Thank you, Paul (you saved me the trouble of having to go and read that tutorial again 😄)
 
Top