Android Question One activity and two layers - the activity menu is invisible

ThePuiu

Active Member
Licensed User
Longtime User
I have an application which at the beginning displays a login window. After checking the credentials I want to delete the current layer and load another layer.
In the second layer I want to display a menu. The problem is that the 3 dots of the menu are visible only after rotating the screen. Used code:
B4X:
Sub Activity_Resume
    If isAutentic = True Then
        Activity.LoadLayout("MainLayout")
        Activity.AddMenuItem("Grafice", "ShowGrafice")
        Activity.AddMenuItem("Valori", "TabelValori")
    Else
        Activity.RemoveAllViews
        Activity.LoadLayout("LoginLayout")
    End If
End Sub

Sub ButtonLogin_Click
    Dim un As String = ""
    Dim psw As String = ""
   
    un = EditUsername.Text.Trim
    psw = EditParola.Text.Trim
    CheckLogin(un, psw)  
End Sub

Sub CheckLogin(un As String, psw As String)
..........
if condition then
isAutentic = true
Activity.RemoveAllViews
Activity.LoadLayout("MainLayout")
Activity.AddMenuItem("Grafice", "ShowGrafice")
Activity.AddMenuItem("Valori", "TabelValori")
end if
End sub
Where am I wrong?
 

DonManfred

Expert
Licensed User
Longtime User
Where am I wrong?
Not using two activities.

The Menu must be set before the first layout is showed (before 1st activity resume). This can onyly be done in activity create.

Load both layouts, hide the one you do not need.

Or better use two activities.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Another solution. Maybe/probably better.

1. Use Appcompat and create a Modifyable Menu.
Add all the menuitems, disable all which belongs to a logged in user only.
2. Use the login in a dialoginterface or such. When finished and the user is successfully logged in; enable the menuitems he now can use.

No need to remove all views and load them again at all. No need for menu recreation as you already have all items you need.
 
Upvote 0

udg

Expert
Licensed User
Longtime User
Yet another way: a single layout where the login related components reside on a panel which is made visible/invisible as needed
If you choose this solution, remember to make the "login panel" as big as the whole Activity area so to hide the "main panel"; you should consume click events on the login panel in order to avoid them to be passed to the underlying main panel (and its components).
Once you have a correct login, you can (select one):
1. remove the login panel
2. disable and hide the login panel, move main panel to foreground
3. hide login panel and move main panel to foreground
Possibly I forgot to mention some details, but you got the idea.
 
Upvote 0
Top