Android Question CustomListView - Items size

LucaMs

Expert
Licensed User
Longtime User
(I hope to explain well enough :D).

I would like to create items of a CustomListView loading a layout and using its "autoscaled dimensions" at runtime (not for real urgent needs, just to avoid to work on my app, as always :D).

To do this, I have decided to create a layout for the item, to load the layout in Activity Main, get the dimensions and create items based on them (dimensions :D).

Well, I failed.

Please, see the attached project. It is a little bit confuse because, after the first unsuccess, I tried to use a CallSubDelayed and then I needed two global module variables.

You can see in red the item layout loaded to get its dimensions (in a real project it will be removed).
Also you can see that "selecting" (touching) an item, you will get a log with the item width and the CustomListView width will be set equal to the "wanted item width" (autoscaled dimensions).


I would like to do other considerations (I should write some of this in new threads):

1) I have noticed that if you call a sub using CallSubDelayed from inside Activity_Create, your sub will be executed only after Activity_Resume (I know that Activity_Resume will start immediately after Activity_Create, but I thought...!)

2) I think it is a good practice to use always a panel as base when you create your layout by Designer, as Erel did it here, so you can see if you anchoreted all views well, without being forced to test it selecting devices (top-right of the Designer). You can then set the panel transparent.

3) I forgot it, writing the first two :p
 

Attachments

  • CLVLayoutTest.zip
    11.9 KB · Views: 200
Last edited:

LucaMs

Expert
Licensed User
Longtime User
3) I forgot it, writing the first two :p
Now I remember.

When you load a layout (Activity_Create) you can access the properties of its views (like Width and Height). If you try to get the properties of a CustomListView (using AsView) you get an error.

I know that CustomListView is not exactly a View, but is there a workaround for this? Is it due to the ability to add your custom views by Designer?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
This question is still open.

I don't know if I did something wrong (please, see the project attached to the first post) but I think there is a "kind of bug" which is related to the base panel and the "add by Designer" feature. I know that, if it is the second hypothesis, only Erel can answer and he's too busy (if so, I can wait months :) because it's only to know, it is surely useful but not urgent).

You can see also the project attached to post #4, which works thanks to an "ugly" workaround.
 
Last edited:
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Why aren't you setting the CLV anchors?
They are always set, as default (top & left). I must not necessarily change them.

I'm sorry but I read the first post 3 times and I still don't understand the question.
The reasons is:
I hope to explain well enough
but I have not been able to do it, as always :D


I create an Item layout by Designer, which base is a Panel. It will be autoscaled, so in Activity_Create I load it to get its autoscaled size. Let's say it has W = 400dip, H = 200dip (already scaled).
Then, to create and add some items to the clv, I call CreateItem, passing W & H to it. Inside CreateItem, as always, a panel will be created using those W & H:
B4X:
    'we need to add the panel to a parent to set its dimensions. It will be removed after the layout is loaded.
    Activity.AddView(p, 0, 0, Width, Height) ' Width & Height are 400dip & 200dip, parameters.
    p.LoadLayout("layItem")
Well, the width of the items created results to be not 400 as I passed, as you can see in Logs when you touch an Item.

I understand why the clv's width is not equal to the items' width, but I don't understand why the items' width is not 400dip, the value I passed as Width to CreateItem.

If you try the project I'm attaching (better logs) and select an Item, you can see the problem better, still watching the logs.


Thank you for your answer, Erel (I repeat, I have no urgency).
 

Attachments

  • CLVLayoutTest2.zip
    11.9 KB · Views: 202
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
The panel's width is later changed to the list width. You can see it in InsertAt sub.
I saw (now ;)), thank you.

Then I think I (we) should use the method I used (project attached).

1) load the Item layout to know its autoscaled size (the layout should have a base panel, which can be transparent);
2) load the Main layout (which contains the CustomListview);
3) set the CLV's width to the Item's width (this must be done after Activity_Resume, so I used CallSubDelayed)

[I used also a CallSubDelayed to fill the clv but we need it only if we fill the clv from Activity_Create]


Is there a better solution? (question for all members ;))


Thank you, Erel
 

Attachments

  • CLVLayout.zip
    11.8 KB · Views: 249
Last edited:
Upvote 0
Top