iOS Question How to open an activity with dynamic name

ThePuiu

Active Member
Licensed User
Longtime User
I want to dynamically build a menu. How can I open an activity based on the Tag property of the pressed item? In B4A it was simple: StartActivity("XXXX") but in B4I? (XXXX.Show)
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
I have done this in previous code.


Setup parameter:
' In starter'
public Activitytostart as Object


' in an activity
Starter.Activitytostart = Main ' or any other activity name

'Finally
StartActivity(Starter.Activitytostart)

Works fine for me.
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Whoops!

try this.
B4X:
'assuming you have 3 pages, page1,page2 and page3 all defined as Page elsewhere
' Note the pages MUST have been previously initialised

sub process_globals

public page as page

' layout with 3 buttons
' all buttons use the button event
private button1 as button
private button2 as button
private button3 as button

end sub

' this can be the same in page1,page2 & page3
public init
if not(page.isinitialized) then
  page.initialize("thispage")
  page.loadlayout("3buttons")


  page1.init
  page2.init
  page3.init
  button1.tag = page1.page
  button2.tag = page2.page
  button3.tag = page3.page
end if

' do other stuff
end sub

sub button_click
private btn as button = sender
private displaypage as page = btn.tag

Main.NavControl.ShowPage(displaypage)
'or
Main.NavControl.SetpagesStack(Array(displaypage))

end sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…