Adding / Removing views

diego

Member
Licensed User
Longtime User
I'm trying to use this function:

Activity.RemoveViewAt(index as int)

but I don't know the view index, just the name (e.g. "myView").

what is the way to use it?

And another question: how to add a View to a ScrollView using the Designer, or change Parent of a view (from Activity to a Scrollview) with code?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub Globals
    Dim Button1 As Button
End Sub
 
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    RemoveView(Button1)
End Sub

Sub RemoveView (V As View)
    For i = 0 To Activity.NumberOfViews - 1
        If Activity.GetView(i) = V Then
            Activity.RemoveViewAt(i)
            Exit
        End If
    Next
End Sub

To change a view's parent, you need to remove it and add it to the new parent.

It is not possible to add views to ScrollView in the designer.
However you can create the required ScrollView layout as a separate layout file.

Then use:
B4X:
ScrollView.Panel.LoadLayout(...)
 
Upvote 0

anuj0sharma

Member
Licensed User
Longtime User
hello there,
i am not able to delete the added views from a layout. views can be seen in the designer but cant be deleted. when i press a delete button a globe appears at the top left corner of the designer.

ps : designer = designer + Emulator
 
Last edited:
Upvote 0

anuj0sharma

Member
Licensed User
Longtime User
In the Designer use Tools -> Remove Selected View.

Thanks man, i m a real fool.. :(
when i was using the default emulator, one with full keyboard and buttons..i was able to delete the views from emulator itself and now i m using a custom one [screen only]. never seen the tool > remove selected view option.
 
Upvote 0

anuj0sharma

Member
Licensed User
Longtime User
removing views

i am loading a layout in a panel and displaying the panel in an activity. now i want to reload the panel with another layout and want all its previously loaded views to be removed [the complete layout].

1. how can i do this??
2. is there any way to group the views and remove all in one shot??
3. is there something i can set the panel as views parent and remove the parent along with all the child??

problem: panel.removeview removes the panel only..not the views of the
layout or the complete layout itself.
work around : removing all the views one by one or in loop, or
hide the unwanted views
 
Upvote 0

anuj0sharma

Member
Licensed User
Longtime User
thanks Erel, was doing something similar in a for loop differently. your suggestion is better.

no 2 and 3 remained unanswered.

MORE TO ASK :
4. how to access process global views and vars from code module and service module.??

5. Erel, is there any book or link available for b4a functions and view's (.properties) ? i mean i was not knowing the use of .NumberOfViews and .GetView methods untill u directed me to the link.

note: I m already referring the link in your signatures.

thanks for the last reply, EREL.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

FMFREAK

Member
Licensed User
Longtime User
It is better to start new threads for new questions.
2, 3) Removing the panel and creating a new one instead will remove all the child views.

Hi Erel,

Can you give a short code on how to do this. I will use a different SUB to remove the panel.
 
Upvote 0
Top