Setting view's parent progmatically

Nyptop

Active Member
Licensed User
Longtime User
Sorry to be asking so many questions but I have spent a couple of days working on this and could not find a solution.

When you write something such as:

B4X:
activity.AddView (ListView1, 100, 300, 80%x, 60%y)

is there something you can add to set the parent of the view?

At the moment the problem I am getting is that the view's (a list view if it makes any difference) parent is automatically the activity and when I change tabs, for example, it simply stays above everything. What I want is for the view to simply stay on the one tab and not go to any of the others.

Find the file in question attached if that helps,

Neil
 

klaus

Expert
Licensed User
Longtime User
You cannot set the Parent property of a view directly in B4A.
You must add the views directly to the right parent view (Panel).
In your case you already have the TabHost layouts on panels, so you should add the new views not onto the Activity but onto the relevant Panel.
Attached your modified project.
Why do you want to add the ListView programaticaly ?
You can add it directly in the Designer, and clear it with ListView1.Clear before filling it with new data (not done in the project I post you) .
In your code, each time you click on the Spinner you add a new ListView so you will get a lot of ListViews after a certain time, or you must always remove the previous one if it does exist.

Best regards.
 
Upvote 0

admac231

Active Member
Licensed User
Longtime User
Have you tried adding your views to a panel then adding the panel to the tab using TabHost.AddTab2("Tab Name",panel)? I haven't had a use for Tabs yet but if I remember rightly that is the best way to use them.

If that tab is only to contain that ListView though you should be fine just adding the ListView on it's own TabHost.AddTab2("Tab Name",listview).
 
Upvote 0
Top