Android Question Custom Buttom using Better Dialog

hdmiacc

Member
Licensed User
Longtime User
hi..

1st this is my code

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim BD As BetterDialogs
    Dim DR As Int
    Dim Button1 As Button
    Dim EditText1 As EditText
    Dim Spinner1 As Spinner
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
  
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub



Sub Button1_Click
  

    'Custom dialog guna Better Dialog
    Dim pnlTitle As Panel
    pnlTitle.Initialize("")
    pnlTitle.LoadLayout("pnldialog")

  
    Dim pnlBody As Panel
    pnlBody.Initialize("")
    pnlBody.LoadLayout("pnldialog2")
    Spinner1.AddAll(Array As String("A","B","C"))
      
    Dim btnOK As Button
    btnOK.Initialize("")
    btnOK.Text = "OK"
  
    Dim btnCancel As Button
    btnCancel.Initialize("")
    btnCancel.Text = "Batal"
  
    DR = BD.CustomDialog(pnlTitle, -1, 60dip, pnlBody, 100%x, 15%y, 0, Null , btnOK, btnCancel, "", True, "CD1")
    If DR = DialogResponse.POSITIVE Then
          

            Button1.Text = EditText1.Text&Spinner1.SelectedItem
          

    End If
End Sub

2nd if my button show
ex2.png

and when i click the button it show "20" at edittext and "A" at spinner. now it show like this..

ex1.png

how to edit my code??
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
EDIT: sorry, I completely missed the fact the views were already added to Globals. So now you just have to set EditText1.Text to 20 after Spinner1.AddAll. If you want to base the values of EditText1 and Spinner1 on the label of your first button, use SubString2 to split the different parts of the text.
 
Last edited:
Upvote 0

hdmiacc

Member
Licensed User
Longtime User
You created your views with the designer (I see two LoadLayout in your code) and you're asking how to edit them, hence my answer. But I probably did not understand the question.

my question is:

My Button1 in Layout1 show 20B. if i re click Button1, i want my custom dialog (contain EditText1 and Spinner1) show 20 in EditText1 and B in Spinner1.

hope u understand my question.. tq.. :)
 
Upvote 0

hdmiacc

Member
Licensed User
Longtime User
EDIT: sorry, I completely missed the fact the views were already added to Globals. So now you just have to set EditText1.Text to 20 after Spinner1.AddAll. If you want to base the values of EditText1 and Spinner1 on the label of your first button, use SubString2 to split the different parts of the text.

how to use substring2? not find any tutorial about it.
 
Upvote 0
Top