Android Tutorial ListView tutorial

Beja

Expert
Licensed User
Question about (ListView1.AddTwoLinesAndBitmap)

This a great example.. it just came when I needed it for a project I am working on..

How can I add about 50 items with different 2 lines.. say the first line is item name or number, the second is the price or description.
item by item or 2-dimentional array? if you give a sample code I will appreciate it as I am not so versed in this.

Thanks in advance
Thanks in advance te
 

klaus

Expert
Licensed User
Where do the data come from an what form (array or file or ?) ?
Depending on this you could probably fill the ListView in a For / Next loop.
Depending on what return value you want when you click on an item you might use AddTwoLinesAndBitmap2 where you can define the return value (object).
 

Beja

Expert
Licensed User
Hi Klaus and thanks for the prompt response..
The data is in a text file that can be editable at runtime (dir internal or SD card) it is like this:
1.jpg, 1.txt, 11.txt
2.jpg, 2.txt, 22.txt
3.jpg, 3.txt, 33.txt
.
.
.
50.jpg, 50.txt, 550.txt
I will need the two text values of all selected items returned. (e.g. 1.txt and 11.txt) do I also need a checkbox inside the item?
Thanks in advance
 

LucaMs

Expert
Licensed User
Hi Klaus and thanks for the prompt response..
The data is in a text file that can be editable at runtime (dir internal or SD card) it is like this:
1.jpg, 1.txt, 11.txt
2.jpg, 2.txt, 22.txt
3.jpg, 3.txt, 33.txt
.
.
.
50.jpg, 50.txt, 550.txt
I will need the two text values of all selected items returned. (e.g. 1.txt and 11.txt) do I also need a checkbox inside the item?
Thanks in advance


checkbox? CheckList (ListView is too simple, I think you should rarely use it)
 

Beja

Expert
Licensed User
Hi Luca,
Could you put the above problem in code?
Thanks in advance..
This is the pseudo code ...

dim str as string
for x = 1 to listcount of listview1
if check(x) is checked then
str = str & item(x) values except the bitmap
next
end if
edittext1.text = str

thanks in advance.
 

klaus

Expert
Licensed User
It depends always on what you want or need.
In Your case as you want having both values x.txt and x1.txt as the return value you can define a String array with both values and set this array as the return value.
In the ItemClick event the return value will be the two items array and you have both data.

Bejas' question is : do I need a CheckBox, not I want a CheckBox?
 

Beja

Expert
Licensed User
Hi Klaus,
Do you think the checkbox as an element of the item gives a visual reminder that the item is already selected, so one does not try to select it again.
Also I want to process the return after selecting all the items I want, instead of one by one. (select the items, revise your selections and then build the return string)
but I don't know how to do this.
 

klaus

Expert
Licensed User
You need to explain exactly what you need or what you want to do !
The questions in your last post are quite different from the question in the first post.
My first post answered the question in your first post.
Explain clearly what you need and then we can answer with an appropriate proposal.
In a 'standard' B4A ListView you can have at most 1 image and 2 labels and a return object and nothing more.
If you want anything else you need another solution.
The solution could be a CustomListView, a CheckList, an UltimateListView, your own ScrollView or your own Class based on a ScollView.
But you need to be clear on what you want and depending on this you could define the best solution with our help.
 

LucaMs

Expert
Licensed User
Given that a text file can not contain pictures, I suppose your file could be:

"ImageFile1.jpg", "Battery", 45
"ImageFile2.jpg", "SmartPhone", 395

I suggest you always use CheckList, even if you do not use the CheckBox, you can choose do not to use and do not show it.

Thank CheckList you have many properties and methods by which you and your user can manage much better the data list.

However, the ListView allows you to receive an object from the event ITEM_CLICK.
You could create a type:
B4X:
Type tItemTexts(Description As String, Price As String)

then, adding an item:
B4X:
Private ItemTexts As tItemTexts
ItemTexts.Initialize
ItemTexts.Description = "text1 from file"
ItemTexts.Price = "text2 from file"
'    lv.AddTwoLinesAndBitmap2("text1FromFile", "text2FromFile", Bmp, ItemTexts)
' OR
    lv.AddTwoLinesAndBitmap2(ItemTexts.Description, ItemTexts.Price, Bmp, ItemTexts)

get the object:
B4X:
Sub lv_ItemClick (Position As Int, Value As Object)
    Private ItemTexts As tItemTexts = Value
log(ItemTexts.Description & " - " & ItemTexts.Price)
End Sub
 

LucaMs

Expert
Licensed User
Klaus, CheckList, as you know, is powerful. You can use it without checkboxes, simply setting a property.

You should (must) create the item layout by code.

I'm thinking of changing this so that you can create your layout using the Designer.

Another function would become CheckList essential and sufficient in any situation:
automatically read the contents of the item.

I do not know if I'll be able to explain this well in English, unfortunately.

Mr. Periklis Koutsogiannis has developed a method by which he obtained the views from a layout and even their names.
Through this method, it would be possible to create a Module (or Class) that automates the receipt of the values of the Item, passing them in a Type or Class.

Since Periklis has been very generous by providing its libraries, he could solve this or post the code in question.


I will point this post to him ;)
 
Last edited:

klaus

Expert
Licensed User
I have never used a CustomListView, a CheckList nor an UltimateListView.
So I would need to look at these before giving a concrete advice.
I prefer that Beja explains us what exactly he needs, instead of guessing what he wants.
 

Beja

Expert
Licensed User
Dears Klaus and Luca,
please look into the attached picture.
thanks in advance.
 

Attachments

  • buildstring.png
    buildstring.png
    30.2 KB · Views: 522

klaus

Expert
Licensed User
Your explanations are still not clear enought on what you want.
So I try to make guess from your posts :
1. You want to display an image and two texts.
1.1 Do you want to edit these texts? Because in your picture it seems that you use EditText views.

2. Do you want multiselection ?
2.1 If yes I think you want to see the selected items (highlighting or something else)

3. Clicking on a Button you want to create a string with ALL items (like in your image in post #192) or only with the selected items ?
3.1. The items all in one, line like in your picture, or each item on its own line ?

Depending on the answers to these questions some Views or CustomViews will work or not !
 

Beja

Expert
Licensed User
Hi Klaus,
Thanks and to your questions:

1. You want to display an image and two texts.
YES

1.1 Do you want to edit these texts? Because in your picture it seems that you use EditText views.
I WANT TO EDIT THE ID NUMBER ONLY. DESCRIPTION IS CONSTANT BUT CAN BE ALTERED OR EDITED BY EDITING THE TEXT FILE OUTSIDE THE APP, OR FROM A SETUP MENU..

2. Do you want multiselection ?
YES.

2.1 If yes I think you want to see the selected items (highlighting or something else)
YES. HIGHLITING OR A CHECK BOX NEXT TO THE ITEM IS OK.

3. Clicking on a Button you want to create a string with ALL items (like in your image in post #192) or only with the selected items ?
ONLY THE SELECTED ITEMS

3.1. The items all in one, line like in your picture, or each item on its own line?
THE THREE ELEMENTS (IMAGE, ID NUMBER AND DESCRIPTION) ARE IN ONE LINE. MY UNDERSTANFING IS, EVERY 3 ELEMENTS REPRESENT 1 LISTVIEW ITEM,
SO FOR CLARITY IT IS BETTER TO BE IN ONE LINE.

Thank you in advance.
 

Beja

Expert
Licensed User
I will point this post to him

No need, Luca..
Enough people know my level of ignorance and no need to promote it through testimonials.
 

Beja

Expert
Licensed User
Just joking!
Periklis is a good man and very helpful. I know that.
 
Last edited:

wmardian

Member
Licensed User
Dear Erel and all B4A forum..
Could you please help me with this;

How can i change the text color of first label on the twolinesLayout listview?
many times i try to change it .. but the color is remain white.. ? :(

Your help will be very appreciated
Thanks and regards
 
Top