Android Tutorial ListView tutorial

eps

Expert
Licensed User
Longtime User
You cannot change the color of the selected item.
If you want it you should use a ScrollView.
There are many ScrollView examples.

Best regards.

Whilst this is true, what you can do, is have 2 ListViews (unless you want to go down the ScrollView route) and then flip between the two, making it appear as if its' changing colour :)
 

askez

Member
Licensed User
Longtime User
diraction

how can i change the scroll view direction to be RTL
i want image to appear right to the text not left
thanx
 

klaus

Expert
Licensed User
Longtime User
You need to adjust the properties of the internal views, the two Labels and the ImageView.
Attached a small test program.
B4X:
Sub Globals
    Dim ListView1 As ListView
    Dim bmp As Bitmap
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim i As Int
    
    bmp.Initialize(File.DirAssets, "Rose.png")
    
    ListView1.Initialize("ListView1")
    Activity.AddView(ListView1, 0, 0, 100%x, 100%y)
    
    ListView1.TwoLinesAndBitmap.ItemHeight = 70dip
    ListView1.TwoLinesAndBitmap.Label.Left = 0
    ListView1.TwoLinesAndBitmap.Label.Top = 0
    ListView1.TwoLinesAndBitmap.Label.Width = ListView1.Width - 70dip
    ListView1.TwoLinesAndBitmap.Label.Height = 40dip
    ListView1.TwoLinesAndBitmap.Label.Gravity = Gravity.CENTER_VERTICAL
    ListView1.TwoLinesAndBitmap.Label.TextSize = 20
    
    ListView1.TwoLinesAndBitmap.SecondLabel.Left = 0
    ListView1.TwoLinesAndBitmap.SecondLabel.Top = 40dip
    ListView1.TwoLinesAndBitmap.SecondLabel.Width = ListView1.Width - 70dip
    ListView1.TwoLinesAndBitmap.SecondLabel.Height = 30dip
    ListView1.TwoLinesAndBitmap.SecondLabel.Gravity = Gravity.CENTER_VERTICAL
    ListView1.TwoLinesAndBitmap.SecondLabel.TextSize = 16
    
    ListView1.TwoLinesAndBitmap.ImageView.Left = ListView1.TwoLinesAndBitmap.Label.Width + 5dip
    ListView1.TwoLinesAndBitmap.ImageView.Top = 5dip
    ListView1.TwoLinesAndBitmap.ImageView.Width = 60dip
    ListView1.TwoLinesAndBitmap.ImageView.Height = 60dip
    ListView1.TwoLinesAndBitmap.ImageView.Gravity = Gravity.FILL
    
    For i = 0 To 20
        ListView1.AddTwoLinesAndBitmap("Line 1" & i, "Line 2" & i, bmp)
    Next
End Sub
Best regards.
 

Attachments

  • ListViewImageRight.zip
    16.3 KB · Views: 778

askez

Member
Licensed User
Longtime User
background color

works great!

can i change the background color between 2 line?
1 - white
2- blue
3- white
4- blue
....
thanx!
 

askez

Member
Licensed User
Longtime User
i've implemented this code and it looks great.
i want picture to come from my DB and not a file.
i've read the tutorials and examples (like flickerview) but i cant manage to combine them with this code.
does anyone has any hint?
thanx!
 

aaronk

Well-Known Member
Licensed User
Longtime User
Hello,

I am using the ListView like below, but lets say I want to change the text for item #4 to something else but want the rest to remain the same.

Do I have to clear the list and re add all the items again or is there a way to only edit 1 item?


lv_single.png
 

Informatix

Expert
Licensed User
Longtime User
You can also use the CheckList class. But if I read you well, your problem is not to insert a new item but to replace an existing content. With CustomListView or CheckList, the code is the same (sv = your scrollview):
B4X:
Dim pnl as panel
pnl = sv.Panel.GetView(3) 'The first position is 0, so for the fourth item, the position is 3
Dim lbl as label
lbl = pnl.GetView(0) 'I suppose that your label is in first position in the item panel
lbl.Text = ... your new text
If you want to change completely the layout and content of your item, CheckList has a function for it: ReplaceItem.
 

pixelpop

Active Member
Licensed User
Longtime User
On the first page of this thread it is stated:

Tips
If you want a single line item with a bitmap (and do not need two lines and a bitmap), you can set the visible property of the second label to false.

I have tried this and also just passed "" as the second label, but the result is the same--the text for the first label is still pushed to the top of the entry. Any chance an update will provide a "SingleLineAndBitmap" option that will vertically center a single line of text on the bitmap?
 

Roger Garstang

Well-Known Member
Licensed User
Longtime User
I have tried this and also just passed "" as the second label, but the result is the same--the text for the first label is still pushed to the top of the entry. Any chance an update will provide a "SingleLineAndBitmap" option that will vertically center a single line of text on the bitmap?

You can move the 1st label down/centered or make it the full item height and set the Gravity (Of the First Label) how you want it aligned.
 

klaus

Expert
Licensed User
Longtime User
Sure it works.

Attached a test program showing it !

B4X:
Sub Globals
    Dim ListView1 As ListView
    Dim bmp As Bitmap
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Dim i As Int
    
    bmp.Initialize(File.DirAssets, "Rose.png")
    
    ListView1.Initialize("ListView1")
    Activity.AddView(ListView1, 0, 0, 100%x, 100%y)
    
    ListView1.TwoLinesAndBitmap.ItemHeight = 70dip
    ListView1.TwoLinesAndBitmap.Label.Left = 0
    ListView1.TwoLinesAndBitmap.Label.Top = 0
    ListView1.TwoLinesAndBitmap.Label.Width = ListView1.Width - 70dip
    ListView1.TwoLinesAndBitmap.Label.Height = 70dip
    ListView1.TwoLinesAndBitmap.Label.Gravity = Gravity.CENTER_VERTICAL
    ListView1.TwoLinesAndBitmap.Label.TextSize = 20
    
    ListView1.TwoLinesAndBitmap.ImageView.Left = ListView1.TwoLinesAndBitmap.Label.Width + 5dip
    ListView1.TwoLinesAndBitmap.ImageView.Top = 5dip
    ListView1.TwoLinesAndBitmap.ImageView.Width = 60dip
    ListView1.TwoLinesAndBitmap.ImageView.Height = 60dip
    ListView1.TwoLinesAndBitmap.ImageView.Gravity = Gravity.FILL
    
    For i = 0 To 20
        ListView1.AddTwoLinesAndBitmap("Line 1" & i, "", bmp)
    Next
End Sub
Best regards.
 

Attachments

  • ListViewOneLineBitmap.zip
    17.4 KB · Views: 598
  • Image.jpg
    Image.jpg
    38.7 KB · Views: 968

Dogbonesix

Active Member
Licensed User
Longtime User
Goto Listview Item

I have been looking but can not find a way to go directly a certain row in a listview?

Such as listview1.selected(12) where 12 is the 12th item in the listview?

It is probably a simple way I just have not found it.
 
Top