Android Question B4XPreferenceDialog Not Showing the Entry Edittext Boxes

Mahares

Expert
Licensed User
Longtime User
Obviously I have a poor understanding of B4XPreferenceDIalog. The entry form displays, but the entry boxes do not display for me to enter a simple First Name and a Last Name. I hope someone can see what I have failed to recognize.
Thank you. I have attached also the project:
B4X:
Sub Globals
    Private txtFirstName As B4XView
    Private txtLastName As B4XView
    Private xui As XUI
    Private Button1 As Button   
    Private prefdialog As PreferencesDialog
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")   ''has only button1
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Activity.finish
End Sub

Sub Button1_Click   
    prefdialog.Initialize(Activity, "Preference Dialog Input", 300dip, 300dip)
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 300dip, 300dip)
    p.LoadLayout("MyDialog")   'has both EditText
    Dim Data As Map = CreateMap("first": txtFirstName.Text,"last": txtLastName.Text)
    Wait For (prefdialog.ShowDialog(Data, "OK", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Dim f As String =txtFirstName.Text
        Dim l As String =txtLastName.Text
        Dim strVar As String =$"My Name is ${f} ${l}"$
        prefdialog.Dialog.Show(strVar, "OK", "", "")
        Log(strVar)
    End If
End Sub
 

Attachments

  • B4XPrefDialogExample021120.zip
    10.2 KB · Views: 189
Last edited:

Mahares

Expert
Licensed User
Longtime User
Start with the examples
I studied and tried to work with the B4A example in the link you mentioned for several hours well before I even posted my thread. I thought all along that I can work in the Android (B4A) environment without having to create a form on the desktop. If there is a way to do it via the Android environment exclusively I am still interested; if not, I have no interest in pursuing B4XPreferencesDialog. I will stick with other methods. Thank you.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
It is very simple.
What is simple to you is most likely not so to others I tried this, but still no go:
B4X:
prefdialog.Initialize(Activity, "Preference Dialog Input", 300dip, 300dip)
    Dim ff As String =prefdialog.AddTextItem("First", txtFirstName.Text)
    Dim ll As String =prefdialog.AddTextItem("Last", txtLastName.Text)
   
    Dim Data As Map = CreateMap("First": ff,"Last": ll)
    Wait For (prefdialog.ShowDialog(Data, "OK", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Dim f As String =txtFirstName.Text
        Dim l As String =txtLastName.Text
        Dim strVar As String =$"My Name is ${f} ${l}"$
        prefdialog.Dialog.Show(strVar, "OK", "", "")
        Log(strVar)
    End If
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is a strong separation between the data and the template. I think that it confuses you. Don't worry you will see that it is simple.
Untested code:
B4X:
'no need to initialize and create the template more than once.
prefdialog.Initialize(Activity, "Preference Dialog Input", 300dip, 300dip)
'TEMPLATE
 prefdialog.AddTextItem("First", txtFirstName.Text)
prefdialog.AddTextItem("Last", txtLastName.Text)
'DATA
    Dim Data As Map = CreateMap(")
    Wait For (prefdialog.ShowDialog(Data, "OK", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Dim f As String = Data.Get("First")
        Dim l As String = Data.Get("Last")
        Dim strVar As String =$"My Name is ${f} ${l}"$
        'prefdialog.Dialog.Show(strVar, "OK", "", "") 'NO NO NO. B4XPreferencesDialog is not a regular dialog. Use B4XDialog for this
        Log(strVar)
    End If
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
You don't need to create a layout.
I was able to make it work using 2 edittext like below, but since no layout is needed, I could not make it Cross-Platform:
B4X:
Sub Globals
    Private txtFirstName As EditText  'I really wanted to use B4XView not Edittext here
    Private txtLastName As  EditText
    Private xui As XUI
    Private prefdialog As PreferencesDialog
End Sub

Sub Activity_Create(FirstTime As Boolean)
    txtFirstName.Initialize("")
    txtLastName.Initialize("")
    prefdialog.Initialize(Activity, "Preference Dialog Input", 300dip, 300dip)
    prefdialog.AddTextItem("First", "First Name")
    prefdialog.AddTextItem("Last",  "Last Name")
'   .......  rest of code here
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
txtFirstName / txtLastName do not do anything and are not required.

B4X:
Sub Globals
    Private xui As XUI
    Private prefdialog As PreferencesDialog
End Sub

Sub Activity_Create(FirstTime As Boolean)
    prefdialog.Initialize(Activity, "Preference Dialog Input", 300dip, 300dip)
    prefdialog.AddTextItem("First", "First Name")
    prefdialog.AddTextItem("Last",  "Last Name")
'   .......  rest of code here
 
Upvote 0
Top