Android Question Generating a new activity

trueboss323

Active Member
Licensed User
Longtime User
How does one create a new activity where the activity needs to be generated (can't normally be done in the designer)? Example: In WhatsApp or other messaging apps , when you click on a conversation , it creates a new activity and retrieves the conversation from the server.
How can I do something like this in B4A?
 

edgar_ortiz

Active Member
Licensed User
Longtime User

I don't see the need to create it on the fly
I previously created in the designer and layout, which will be called when "the user click on a conversation"
 
Upvote 0

LucasHeer

Active Member
Licensed User
Longtime User
I usually spawn a panel on top of the current panel, setting the background color to white or like f6f6f6.

My pageHandler/navigation is just a simple list of panels. When I wish to add a page, i add a panel to the main view, and then when I need to remove the topmost, i remove the size - 1.
 
Upvote 0

LucasHeer

Active Member
Licensed User
Longtime User
Do you have a project example?

Just create your initial activity/view with a master panel that will load layouts.


I like to create my own navigation system that works with B4J/B4A/B4i all. Here's how I do it:

1. Define what you want each page to have: (Could just be a list of panels, but all of my pages have titles as well.)
B4X:
Type navigationPage (viewTitle As String, viewPanel As Panel)

2. Add your page definition to your global variables.
B4X:
Public navPages As List

3. Make your Add/Back/Clear methods:
B4X:
public Sub addPage1(navPage As navigationPage)
    If(navPages.IsInitialized = False) Then
        navPages.Initialize
    End If
    navPages.Add(navPage) 'Add navpage to page list
    contentView.AddView(navPage.viewPanel, 0,0,contentView.Width, contentView.height) 'add this to the top of our master panel
End Sub

public Sub backPage1()
    If(navPages.IsInitialized And navPages.Size > 1) Then
        Dim iNavPage As navigationPage = navPages.Get(navPages.Size - 1) 'get the topmost panel
        iNavPage.viewPanel.RemoveView() 'remove the view from contentPanel
        navPages.RemoveAt(navPages.Size - 1) 'remove the navPage from our list
    End If
End Sub

public Sub clearPages1()
    If(navPages.IsInitialized) Then
        navPages.Clear() 'clear page list
    End If
    contentView.RemoveAllViews() 'clear all views inside of master panel
End Sub

Add A Page:
B4X:
public Sub testAdd()
    Dim navNewsPage As navigationPage
 
    Dim p As Panel
    p.Initialize("")
    p.SetLayout(0, 0, contentView.Width, contentView.height)
    p.LoadLayout("newssubscriptiontabcard")
 
    navNewsPage.viewPanel = p
    navNewsPage.viewTitle = "News Feed"
    addPage1(navNewsPage, 0)
End Sub

Again, this is just how I do it. This is the only view I load to the activity. The rest of my views are loaded and STACKED on top of each other in the main content panel.


I make my own titleBar and NavBar so that I can copy/paste directly from iOS. You could make the entire main view a single panel, and load each of your pages. You will need to have a back button to delete the top-most view.

Heres my designer script for the contentView: (You could just use anchors)
B4X:
contentView.Left = 0
contentView.Top = titlePanel.Bottom
contentView.Height = navigationPanel.Top - titlePanel.Bottom
contentView.Width = 100%x
 

Attachments

  • upload_2019-12-15_2-14-4.png
    20.9 KB · Views: 84
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…