Android Question [Solved] how to make all items right aligned in preference dialog ?

AnandGupta

Expert
Licensed User
Longtime User
Some items show left aligned and some right aligned in preference-dialog.


how to make all items right aligned ?
 
Solution
B4X:
For i = 0 To prefdialog.PrefItems.Size - 1
        Dim pi As B4XPrefItem = prefdialog.PrefItems.Get(i)
        If pi.ItemType = prefdialog.TYPE_TEXT Then
            Dim ft As B4XFloatTextField = prefdialog.CustomListView1.GetPanel(i).GetView(0).Tag
            ft.TextField.SetTextAlignment("CENTER", "RIGHT")
            If ft.Text.Contains("soccer") Then ft.TextField.SetTextAlignment("CENTER", "LEFT")
        End If
    Next

Mahares

Expert
Licensed User
Longtime User
B4X:
For i = 0 To prefdialog.PrefItems.Size - 1
        Dim pi As B4XPrefItem = prefdialog.PrefItems.Get(i)
        If pi.ItemType = prefdialog.TYPE_TEXT Then
            Dim ft As B4XFloatTextField = prefdialog.CustomListView1.GetPanel(i).GetView(0).Tag
            ft.TextField.SetTextAlignment("CENTER", "RIGHT")
            If ft.Text.Contains("soccer") Then ft.TextField.SetTextAlignment("CENTER", "LEFT")
        End If
    Next
 
Upvote 1
Solution

AnandGupta

Expert
Licensed User
Longtime User
I extended the code as below to get the desired results,
B4X:
    For i = 0 To pref.PrefItems.Size - 1
        Dim pi As B4XPrefItem = pref.PrefItems.Get(i)
        If pi.ItemType = pref.TYPE_TEXT Then
            Dim ft As B4XFloatTextField = pref.CustomListView1.GetPanel(i).GetView(0).Tag
            ft.TextField.SetTextAlignment("CENTER", "RIGHT")
'            If ft.Text.Contains("soccer") Then ft.TextField.SetTextAlignment("CENTER", "LEFT")
        else If pi.ItemType = pref.TYPE_MULTILINETEXT Then
            Dim ft As B4XFloatTextField = pref.CustomListView1.GetPanel(i).GetView(0).Tag
            ft.TextField.SetTextAlignment("CENTER", "RIGHT")
'            If ft.Text.Contains("soccer") Then ft.TextField.SetTextAlignment("CENTER", "LEFT")
        Else If pi.ItemType = pref.TYPE_NUMBER Then
            Dim ft As B4XFloatTextField = pref.CustomListView1.GetPanel(i).GetView(0).Tag
            ft.TextField.SetTextAlignment("CENTER", "RIGHT")
'            If ft.Text.Contains("soccer") Then ft.TextField.SetTextAlignment("CENTER", "LEFT")
        End If
    Next

 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I extended the code
You can shorten your code to this and it will work:
B4X:
For i = 0 To pref.PrefItems.Size - 1
        Dim pi As B4XPrefItem = pref.PrefItems.Get(i)
        If pi.ItemType = pref.TYPE_TEXT Or  pi.ItemType = pref.TYPE_MULTILINETEXT  Or pi.ItemType = pref.TYPE_NUMBER Then
            Dim ft As B4XFloatTextField = pref.CustomListView1.GetPanel(i).GetView(0).tag
            ft.TextField.SetTextAlignment("CENTER", "RIGHT")
        End If
    Next
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…