Android Question display a button in several activities

sultan87

Active Member
Licensed User
Longtime User
Hello,
I want to display a button in several activities. the click event is the same for all activities
how to do ?
 

klaus

Expert
Licensed User
Longtime User
What exactly do you want to achieve ?
You cannot have the same button on different activities.
You need one button per activity. In the Button_Click event in each activity you could call a routine in a code module.
But without knowing what exactly you need it's difficult to give a concrete advice.
 
Upvote 0

sultan87

Active Member
Licensed User
Longtime User
Thank's for your response
I have in every activity a button to exit the application (no activity.finish)
This button is always positioned in the same place and always the same event
 
Upvote 0

sultan87

Active Member
Licensed User
Longtime User
It would be easier to answer if you posted what you have done instead of letting us to expect to try to guess what you could have donne !
Hello,
I'm sorry, here is the code used

Le module
B4X:
Sub Pnl_Entete As Panel
  
    Dim Pnl As Panel
    Dim icon_gest_therm As ImageView  
    Dim lbl_titre As Label
    Dim icon_quitter_appli As ImageView
  
    Pnl.Initialize("")
    Pnl.Color = Colors.Transparent
  
    icon_gest_therm.Initialize("")
    icon_gest_therm.Bitmap = LoadBitmap(File.DirAssets,"icon_gest_therm.png")
    icon_gest_therm.Gravity = Gravity.FILL
    Pnl.AddView(icon_gest_therm,0,0,40*Main.Coeff_X,40*Main.Coeff_y)
  
    lbl_titre.Initialize("")
    lbl_titre.Text = "Gestion du Thermostat"
    lbl_titre.TextSize = 10
    lbl_titre.Gravity = Gravity.CENTER
    lbl_titre.Color=Colors.ARGB(0,0,255,0)
    lbl_titre.TextColor = Colors.Green
    Pnl.AddView(lbl_titre, 50*Main.Coeff_X, 0*Main.Coeff_Y, 100*Main.Coeff_X, 50*Main.Coeff_Y)

    icon_quitter_appli.Initialize("quitter_appli")
    icon_quitter_appli.Bitmap = LoadBitmap(File.DirAssets,"icon_quitter.png")
    icon_quitter_appli.Gravity = Gravity.FILL
    Pnl.AddView(icon_quitter_appli,420,0,40*Main.Coeff_X,40*Main.Coeff_y)  
  
    Return Pnl
      
End Sub

The Activity

B4X:
Sub Activity_Resume
  
    If Main.Quit_Appli Then
        Activity.Finish
    End If

' Entète

    Activity.Color = Colors.Gray
  
    Activity.AddView(Sous_Prog.Pnl_Entete,0*Main.Coeff_X,0*Main.Coeff_y,480*Main.Coeff_X,50*Main.Coeff_y)

End Sub

Sub quitter_appli_click
  
   Dim Reponse As Int
  
   Reponse = Msgbox2("Voulez vous vraiment quitter la Gestion du Thermostat","Quitter","Oui","","Non",Null)  
   If Reponse = DialogResponse.Positive Then
     Main.Quit_Appli = True
     Activity.Finish
   End If
      
End Sub

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