Android Question CustomListView Set default ItemHeight

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All

A question on setting the item height in a CustomListView.
I have found several references to "Changing the height of an existing item but requires each item to be independently changed.

In ListView I would do this:
B4X:
AllListView.SingleLineLayout.Label.Height = 40dip
    AllListView.SingleLineLayout.ItemHeight = AllListView.SingleLineLayout.Label.Height

and
B4X:
AllListView.Clear                        'Clear Listview before populating or else you get duplicates   
    AllListView.AddSingleLine2("About",14)
    AllListView.AddSingleLine2("Help",14)
    AllListView.AddSingleLine2("Settings",14)
    AllListView.AddSingleLine2("Export Function",14)
    AllListView.AddSingleLine2("Import Function",14)

would build a Lisview where Label and Item are all 40dip.


In CustomListView I have found AllListView.DesignerLabel.Height = 40dip gives a Label height but nothing to preset the ItemHeight.


I am sure it is in there somewhere, but at the moment I get Labels 40dip and Items much bigger.

Thanks in advance
Regards Roger
 

Mahares

Expert
Licensed User
Longtime User
In CustomListView I have found AllListView.DesignerLabel.Height = 40dip gives a Label height but nothing to preset the ItemHeight.
When you create your items, ( here is an example), the item height is 90dip in this sample:
B4X:
Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0,CustomListView1.AsView.Width, 90dip)
    p.LoadLayout("Item")
'rest of code
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
When you create your items, ( here is an example), the item height is 90dip in this sample:
B4X:
Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0,0,0,CustomListView1.AsView.Width, 90dip)
    p.LoadLayout("Item")
'rest of code

Mahares
Thanks for the reply but I must be thick. I can't see how I get from what you have shown to a CLV with a list of items. [Could be in the "rest of code"]
From Erels post I infer that I should using something other than AddTextItem.

Below is the code I have that does not work as required.

B4X:
Sub AllListViewSub
    'A Sub that sets the default parameters of the Labels in a CLV
    AllListView.GetBase.Height = 100%y - lblAllTitle.Height
    AllListView.getbase.Top = lblAllTitle.Height
    AllListView.DesignerLabel.Gravity = Bit.Or(Gravity.LEFT, Gravity.CENTER_VERTICAL)
    AllListView.DesignerLabel.TextColor = Colors.RGB(13,136,191)
    AllListView.DesignerLabel.TextSize = 14
    AllListView.DesignerLabel.Color = Colors.RGB(252,252,252)
    AllListView.DesignerLabel.Height = 40dip
    lblAllTitle.Top = 0
    btnAllListBack.Top = 0
End Sub

Sub btnGUIMenu_Click
    'Change ListView from default to the Menu
    AllListView.getbase.Height = 160dip
    AllListView.getbase.Top = 100%y - 160dip
    lblAllTitle.Top = AllListView.getbase.Top - lblAllTitle.Height
    btnAllListBack.Top = lblAllTitle.Top   
    AllListView.DesignerLabel.Gravity =   Bit.Or(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    

    'Sets CLV as MENU
    AllListView.DesignerLabel.Gravity =  Bit.Or(Gravity.CENTER_VERTICAL, Gravity.CENTER_HORIZONTAL)
    AllListView.Clear                                        'Clear CLV before populating or else you get duplicates
    AllListView.AddTextItem("About",0)                   
    AllListView.AddTextItem("Settings",0)                 
    AllListView.AddTextItem("Actions",0)                   
    lblAllTitle.Text = "MENU"
    btnAllListBack.Text = "<<<"
    
    pnlAllLists.Elevation = 4dip   
End Sub

Roger
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I can't see how I get from what you have shown to a CLV with a list of items
Hi Roger: You are probably asleep as I write this. But, most of the formatting properties you are showing in your listview, you can do in the Designer of customlistview layout as shown in the attached project. In the project, I create a list of items and display them on the xCLV. The layout file is called: 1
I have created this project to give you an idea how you get from a list of text items to display inside an xCLV. In this case, using addTextItems xCLV methods. It can get more elaborate when you add other layouts with different types of views, like checkbox, B4Xswitch, labels, edittext, buttons, etc.
Unzip and run this project to see how it works and look at its code. Once you start getting comfortable with xCLV, , also seeing the videos and threads, you probably will not be interested in ListView anymore, but you start liking xCLV much better and start exploring its broader features.
 

Attachments

  • xCLVSimplestFormForRoger.zip
    8.4 KB · Views: 168
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi Roger: You are probably asleep as I write this. But, most of the formatting properties you are showing in your listview, you can do in the Designer of customlistview layout as shown in the attached project. In the project, I create a list of items and display them on the xCLV. The layout file is called: 1
I have created this project to give you an idea how you get from a list of text items to display inside an xCLV. In this case, using addTextItems xCLV methods. It can get more elaborate when you add other layouts with different types of views, like checkbox, B4Xswitch, labels, edittext, buttons, etc.
Unzip and run this project to see how it works and look at its code. Once you start getting comfortable with xCLV, , also seeing the videos and threads, you probably will not be interested in ListView anymore, but you start liking xCLV much better and start exploring its broader features.

Thanks Mahares,
Yes you are right I've just crawled out of bed.
I put the formatting in the code as I change it back and forth for different lists.
I really appreciate the trouble you've taken, it will give me plenty to work through and hopefully the brain cells will click.
I have already committed to dump listview in favour of CLV so I will make it work.

Many thanks again, I will post the result when I get there
Regards Roger
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi Roger: You are probably asleep as I write this. But, most of the formatting properties you are showing in your listview, you can do in the Designer of customlistview layout as shown in the attached project. In the project, I create a list of items and display them on the xCLV. The layout file is called: 1
I have created this project to give you an idea how you get from a list of text items to display inside an xCLV. In this case, using addTextItems xCLV methods. It can get more elaborate when you add other layouts with different types of views, like checkbox, B4Xswitch, labels, edittext, buttons, etc.
Unzip and run this project to see how it works and look at its code. Once you start getting comfortable with xCLV, , also seeing the videos and threads, you probably will not be interested in ListView anymore, but you start liking xCLV much better and start exploring its broader features.


Mahares
Finally found time to look at your example.
Unfortunately it only tells me what I already know [AddTextItem]. It doesn't solve the problem of how to set the height of an item and doesn't tell me how get from your code in #2 to an actual list.

Sorry I'm back to the original question and trying to follow Erel's Video tutorial.

Regards Roger
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Unfortunately it only tells me what I already know [AddTextItem]. It doesn't solve the problem of how to set the height of an item
If you read Erel's answer way back in post #3, since we are using the AddTextItem method for the xCLV, here is what he said: the height depends on the text length. It measures the text so the full text will be visible. That is what the project I posted addresses.

doesn't tell me how get from your code in #2 to an actual list.
What was described in post#2 is the other way of using xCLV by creating item layouts, and loading them onto panels, and it can incorporate more than just adding text items. You can add all kind of views, images, labels, edittext, etc.. Then you will be able to control the item height at will. Since you are just feeling your way into xCLV, it was only prudent to show you an example (using AddTextItem) closest to a listview until you start feeling comfortable. Now, that you started viewing videos code samples in forum and tutorials, you should start seeing the differences.
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
You can also check @ADeveloper CLV Video here


mcqueccu,
I've had a short look at this video and it looks really good the presenter takes things reeealy slow. I like that.
I will get back to it when life stops getting in the way, fairly sure it will get the message through to my brain.

Roger
 
Upvote 0
Top