Android Question Change Width of Inputlist [SOLVED]

AHilberink

Active Member
Licensed User
Longtime User
Hi,

Is there a way to change the width of an Inputlist? I want to prevent twoliners.

Kind regards,
André
 
Solution
The InputList function in B4A is deprecated.
Msgbox and other modal dialogs are deprecated. Use the async methods instead. (warning #34)
The B4XDialog (XUI Views library) with a B4XListTemplate (mentioned by @zed ) is a good alternative.
Some sample code:
B4XDialog with B4XListTemplate:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Public keuzedialog As B4XDialog
End Sub
Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub
Private Sub Button1_Click
    keuzedialog.Initialize(Root)
    keuzedialog.PutAtTop = True
    keuzedialog.BackgroundColor = Colors.White
    Dim width As Int =...

PaulMeuris

Active Member
Licensed User
Can you show some code where you use an "Inputlist"?
Which variable type do you refer to with "Inputlist'"?
If you ask the right question then you might get the answer you are looking for...
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
Can you show some code where you use an "Inputlist"?
Which variable type do you refer to with "Inputlist'"?
If you ask the right question then you might get the answer you are looking for...
Hi,

Of course:
B4X:
            Dim Keuze(Cursor1.RowCount) As String
            Dim Nummer(Cursor1.RowCount) As String

            For i = 0 To Cursor1.RowCount - 1
                Cursor1.Position = i

                Keuze(i)=Cursor1.GetString("ProjectID")&" - "&Cursor1.GetString("Naam")
                Nummer(i)=Cursor1.GetString("ProjectID")
            Next
            ProgressDialogHide

            Dim Ret As Int
            Ret = InputList(Keuze,"Projecten",-1)
       
            If Ret = DialogResponse.CANCEL Then
                ToastMessageShow("Afgebroken", False)
                CurrentProjectID = ""
            Else
                CurrentProjectID = Nummer(Ret)
            End If

"Keuze" has a Number and a Name. This name is mostly longer than the with of the Inputlist, so I got 2 lines. I hope there is a way to set Width of the Inputlist.

Thanks,
André
 
Upvote 0

zed

Active Member
Licensed User
What is inputlist?
You mean that "Keuze" is not displayed on a single line because the string is too long?

I don't understand your question.
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
What is inputlist?
You mean that "Keuze" is not displayed on a single line because the string is too long?

I don't understand your question.

InputList is a build in function of B4A (MsgBox). You are correct: My problem is "because the string is too long" or the box is too narrow. I hope there is a way to set the Width of the box.
 
Upvote 0

PaulMeuris

Active Member
Licensed User
The InputList function in B4A is deprecated.
Msgbox and other modal dialogs are deprecated. Use the async methods instead. (warning #34)
The B4XDialog (XUI Views library) with a B4XListTemplate (mentioned by @zed ) is a good alternative.
Some sample code:
B4XDialog with B4XListTemplate:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Public keuzedialog As B4XDialog
End Sub
Public Sub Initialize
    B4XPages.GetManager.LogEvents = True
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
End Sub
Private Sub Button1_Click
    keuzedialog.Initialize(Root)
    keuzedialog.PutAtTop = True
    keuzedialog.BackgroundColor = Colors.White
    Dim width As Int = GetDeviceLayoutValues.Width - 10dip
    Dim height As Int = GetDeviceLayoutValues.Height - 100dip
    Dim keuzelst As List
    keuzelst.Initialize
    keuzelst.Add("id1 - een heel lange tekst voor de eerste keuze die normaal gezien niet op 1 regel kan.")
    keuzelst.Add("id2 - een korte tekst")
    keuzelst.Add("id3 - een redelijk korte naam")
    Dim listtpl As B4XListTemplate
    listtpl.Initialize
    listtpl.Resize(width,height)
    listtpl.Options = keuzelst
    listtpl.CustomListView1.AsView.SetLayoutAnimated(0, 0dip, 0dip, width - 10dip, height)
    listtpl.CustomListView1.sv.SetLayoutAnimated(0, 0dip, 0dip, width - 10dip, height)
    listtpl.CustomListView1.DefaultTextBackgroundColor = xui.Color_White
    listtpl.CustomListView1.DefaultTextColor = xui.Color_Black
    keuzedialog.ButtonsHeight = 50dip        ' set to 1dip to force the user to select
    Wait For (keuzedialog.ShowTemplate(listtpl, "", "", "Cancel")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        xui.MsgboxAsync(listtpl.SelectedItem,"Selected item")
    End If
End Sub

But as you can see the first line is still longer than one line. The CustomListView from the template uses text items.

Another way to use a list is to use a B4XDialog with a custom layout.
B4XDialog with custom layout:
Private Sub Button1_Click
    keuzedialog.Initialize(Root)
    keuzedialog.PutAtTop = True
    keuzedialog.BackgroundColor = Colors.White
    Dim width As Int = GetDeviceLayoutValues.Width - 10dip
    Dim height As Int = GetDeviceLayoutValues.Height - 100dip
    Dim keuzelst As List
    keuzelst.Initialize
    keuzelst.Add("id1 - een heel lange tekst voor de eerste keuze die normaal gezien niet op 1 regel kan.")
    keuzelst.Add("id2 - een korte tekst")
    keuzelst.Add("id3 - een redelijk korte naam")   
    Dim pnl As B4XView = xui.CreatePanel("")
    pnl.SetLayoutAnimated(0dip, 0dip, 0dip,width - 10dip, height)
    pnl.LoadLayout("keuzedialog_layout")
    fill_clv1
    Dim rsub1 As ResumableSub =  keuzedialog.ShowCustom(pnl, "OK", "", "")
    Wait For (rsub1) Complete (Result As Int)
    If Result = xui.dialogResponse_Positive Then
        '
    End If
End Sub
Private Sub fill_clv1
    For i = 0 To keuze.Length -1
        Dim pnl As Panel = clv1_item(keuze(i))
        clv1.Add(pnl,i)
    Next
End Sub
Private Sub clv1_item(naam As String) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0dip, 0dip, clv1.AsView.Width,40dip)
    p.LoadLayout("clv1item_layout")
    lblnaam.Text = naam
    Return p
End Sub
Private Sub clv1_ItemClick (Index As Int, Value As Object)
    Log(clv1.GetValue(Index))
    clv1.GetPanel(Index).GetView(0).Color = xui.Color_Green
End Sub

In the custom layout (clv1item_layout) the lblnaam label Single Line property is checked. This causes the text to be truncated.
You can also use a B4XComboBox that also has a Single Line property you can check.

Or you can use a Spinner.


To answer your question: i don't think it is possible to set the items from an InputList to a single line (no wrapping).
 
Upvote 0
Solution

AHilberink

Active Member
Licensed User
Longtime User

Thanks Paul for all these options. I will replace the InputList and try which of your options will fit the most.

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