Android Tutorial ListView tutorial

GeordieJenner

Member
Licensed User
Longtime User
more complex listview item

unless i am reading this incorrectly, the item seems limiting. i have created a control (or view) with say 10 labels on in, some graphics (like a checkmark for completed), see attached image as ListView Item. is there a way to add a panel to the listview, with a LoadLayout so as to display my view?
 

Attachments

  • ListView Item.jpg
    ListView Item.jpg
    10.8 KB · Views: 6,247

GeordieJenner

Member
Licensed User
Longtime User
worked perfect, thanks. now, on that 'view' are labels i wish to alter the text. my svload looks like this:
For intX=0 To 12
Dim p As Panel
p.Initialize("")
p.LoadLayout("ctrlAppointmentItem")
svAppointments.Panel.AddView(p,0,intX*61,1080,60)
Next
svAppointments.Panel.Height=13*61
after the dim p, i wish to do something like p.lblName.text = "bob"

suggestions...
btw, i have been using this for about 48 hours and found it incredibly easy to pick up. thanks
 

GeordieJenner

Member
Licensed User
Longtime User
actually, kind of got this, just a little help. it appears i have to loop through the view's, but i cannot compare to the label.Name? my test on the label.left worked, but it is not property i wish to compare to.
p.LoadLayout("ctrlAppointmentItem")
For i = 0 To p.NumberOfViews - 1
Dim v As View
Dim l As Label
v = p.GetView(i)
If v Is Label Then
l=v
If l.Left=140 Then
l.Text=intX
End If
End If
Next
 

kickaha

Well-Known Member
Licensed User
Longtime User
The best way to handle this is to use the labels Tag property. Set the tag property of each label to something meaningful, then your code would be
B4X:
p.LoadLayout("ctrlAppointmentItem")
For i = 0 To p.NumberOfViews - 1
Dim v As View
Dim l As Label
v = p.GetView(i)
If v Is Label Then
l=v
If l.Tag = "intX Label" Then '  "intX Label" used as an example
l.Text=intX
End If
End If
Next
 

GeordieJenner

Member
Licensed User
Longtime User
interesting, but i there is no IsReadOnly property, so the user could edit it. Is there binding available ItemsSource or DataContext?
 

kickaha

Well-Known Member
Licensed User
Longtime User
I think the main point is if you are not going to allow the user to edit the text, do NOT use an EditText - a label is a better option from both the coding and the appearance point of view.
 

klaus

Expert
Licensed User
Longtime User
Sorry, I probably misunderstood between 'alter the text' and interpreted it as 'edit the text'. The text can be changed (altered) in Labels.
I fully agree with kickaha in using Labels.
The Tag would also have been necessary for EditText views.

Best regards.
 

Widget

Well-Known Member
Licensed User
Longtime User
Background optimization
There is a hidden assumption that the background behind the ListView is solid black. If you set the background to something else like a gradient background or image you will see that during scrolling the background disappears.
You can change the background scrolling color with the ScrollingBackgroundColor property. If the background is not solid color set it to Colors.Transparent.

Example (the activity background is a gradient):
B4X:
    Dim GD As GradientDrawable
    GD.Initialize("TR_BL", Array As Int(Colors.Gray, Colors.LightGray))
    Activity.Background = GD
    ListView1.ScrollingBackgroundColor = Colors.Transparent
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 used the code above but I wasn't able to get my ListView1 to be transparent unless I went to the Designer and set Alpha to 0. I thought ListView1.ScrollingBackgroundColor = Colors.Transparent would be the same as setting Alpha to 0.

Is there a difference?

TIA
Widget
 

Koushik

Member
Licensed User
Longtime User
Hi,
I am very new to Basic4Android.
I need to create some UI as attached in the screenshot. This is basically to list items with a bitmap and two labels at the bottom similar as Android home screen. The number of items will be determined during runtime.

Please suggest if it is possible using ListView. Otherwise what is the best approach to achieve similar UI as Android home screen.:sign0085:

Regards,
Koushik
 

Attachments

  • items.jpg
    items.jpg
    29.9 KB · Views: 4,704
Top