Android Question B4XPreferencesDialog adjust views of Short_Options dialog

RB Smissaert

Well-Known Member
Licensed User
Longtime User
With the Short_Options we get in the dialog from left to right:
The title, the current value of the variable to be changed and then the drop-down button to show the different options.
All works OK, except the the width of the view that holds the current value is too small, so the value is truncated.

I have the following 4 options:
14/12/2020
14/Dec/2020
Mon 14/12/2020
Mon 14/Dec/2020

to be picked to set the date format of a flexible table in my app.

When the current value is 14/12/2020 I get:
14/12/20..

The problem is I can't figure out what view holds the current value.

This is the Sub that loads and shows the dialog. None of the logs tells me what view I have to adjust to full current value showing.

B4X:
Private Sub btnGeneralSettings_Click
    
    Dim n As Int
    
    LoadPreferencesDialog(2, 35, 55, True)
    
    Dim pd As Object = prefdialog.ShowDialog(arrOptions(iOptionsIndex), "OK", "CANCEL")
    
    Dim pnl As B4XView = prefdialog.CustomListView1.GetPanel(20)
    
    Log("pnl.GetView(0).Left: " & pnl.GetView(0).Left)
    Log("pnl.GetView(0).Text: " & pnl.GetView(0).Text)
    
    For Each v As B4XView In pnl.GetAllViewsRecursive
        Log(n & ": pnl view left and width: " & v.Left & " - " &  v.Width)
        n = n + 1
        Try
            Log(n & ": v.Text: " & v.Text)
        Catch
            Log(n & ": error")
            Continue
        End Try
    Next
    
    n = 0

    Dim lbl As B4XView = pnl.GetView(1)
    'this view (lbl) has only one child view
    '---------------------------------------
    
    Log("lbl.Left: " & lbl.Left)
    Log("lbl.Width: " & lbl.Width)

    For Each v As B4XView In lbl.GetAllViewsRecursive
        Log(n & "l: bl view left and width: " & v.Left & " - " &  v.Width)
        n = n + 1
    Next
    
    Log("lbl.Parent.Width: " & lbl.Parent.Width)
    Log("Root.Width: " & Root.Width)
    lbl.SetLayoutAnimated(0, 80dip, lbl.Top, 400dip, lbl.Height)
    
    Wait For (pd) Complete (Result As Int)
    
    If Result = xui.DialogResponse_Positive Then
        SaveOptions
    End If
    
    cMP.HideKeyboard
 End Sub

RBS
 

RB Smissaert

Well-Known Member
Licensed User
Longtime User
With the Short_Options we get in the dialog from left to right:
The title, the current value of the variable to be changed and then the drop-down button to show the different options.
All works OK, except the the width of the view that holds the current value is too small, so the value is truncated.

I have the following 4 options:
14/12/2020
14/Dec/2020
Mon 14/12/2020
Mon 14/Dec/2020

to be picked to set the date format of a flexible table in my app.

When the current value is 14/12/2020 I get:
14/12/20..

The problem is I can't figure out what view holds the current value.

This is the Sub that loads and shows the dialog. None of the logs tells me what view I have to adjust to full current value showing.

B4X:
Private Sub btnGeneralSettings_Click
   
    Dim n As Int
   
    LoadPreferencesDialog(2, 35, 55, True)
   
    Dim pd As Object = prefdialog.ShowDialog(arrOptions(iOptionsIndex), "OK", "CANCEL")
   
    Dim pnl As B4XView = prefdialog.CustomListView1.GetPanel(20)
   
    Log("pnl.GetView(0).Left: " & pnl.GetView(0).Left)
    Log("pnl.GetView(0).Text: " & pnl.GetView(0).Text)
   
    For Each v As B4XView In pnl.GetAllViewsRecursive
        Log(n & ": pnl view left and width: " & v.Left & " - " &  v.Width)
        n = n + 1
        Try
            Log(n & ": v.Text: " & v.Text)
        Catch
            Log(n & ": error")
            Continue
        End Try
    Next
   
    n = 0

    Dim lbl As B4XView = pnl.GetView(1)
    'this view (lbl) has only one child view
    '---------------------------------------
   
    Log("lbl.Left: " & lbl.Left)
    Log("lbl.Width: " & lbl.Width)

    For Each v As B4XView In lbl.GetAllViewsRecursive
        Log(n & "l: bl view left and width: " & v.Left & " - " &  v.Width)
        n = n + 1
    Next
   
    Log("lbl.Parent.Width: " & lbl.Parent.Width)
    Log("Root.Width: " & Root.Width)
    lbl.SetLayoutAnimated(0, 80dip, lbl.Top, 400dip, lbl.Height)
   
    Wait For (pd) Complete (Result As Int)
   
    If Result = xui.DialogResponse_Positive Then
        SaveOptions
    End If
   
    cMP.HideKeyboard
 End Sub

RBS
Sorted this all out now, with some minor additions to B4XPreferences.b4xlib:

B4X:
Sub Class_Globals
    Private miComboxWidth As Int
    Private miComboxLeft As Int

Public Sub getComboBoxWidth As Int
    Return miComboxWidth
End Sub

Public Sub setComboBoxWidth(iComboBoxWidth As Int)
    miComboxWidth = iComboBoxWidth
End Sub

Public Sub getComboBoxLeft As Int
    Return miComboxLeft
End Sub

Public Sub setComboBoxLeft(iComboBoxLeft As Int)
    miComboxLeft = iComboBoxLeft
End Sub

Public Sub ShowDialog (Data As Map, Yes As Object, Cancel As Object) As ResumableSub

    If CustomListView1.Size = 0 Then
        Dim LastTextField As B4XFloatTextField
        For Each pi As B4XPrefItem In PrefItems
            Dim pnl As B4XView = CreateLayouts(pi)
            CustomListView1.Add (pnl, pi)
            If pnl.GetView(0).Tag Is B4XFloatTextField Then
                Dim tf As B4XFloatTextField = pnl.GetView(0).Tag
                If LastTextField.IsInitialized Then
                    LastTextField.NextField = tf
                End If
                LastTextField = tf
            Else
                If pi.ItemType = TYPE_SHORTOPTIONS Then
                    If miComboxLeft > 0 Then
                        pnl.GetView(1).Left = miComboxLeft '<<<<
                    End If
                    If miComboxWidth > 0 Then
                        pnl.GetView(1).Width = miComboxWidth '<<<<
                    End If
                End If    
            End If
        Next

'In Private Sub CreateLayouts:
        Case TYPE_SHORTOPTIONS
            p.LoadLayout("shortoptions") 'this has the views Label1 and B4XComboBox1, p is a newly created panel
            p.GetView(0).TextColor = TextColor
            If miComboxWidth > 0 Then
                B4XComboBox1.mBase.GetView(0).Width = miComboxWidth '<<<<
            End If

All is optional, so it won't affect existing code using the original B4XPreferencesDialog.b4xlib.
I guess this all can be done without altering the b4xlib source code, but I prefer this neater and simpler way.
Just must remember to replace the library after a B4A version update.

RBS
 
Upvote 0
Top