Android Question B4XDateTemplate - Change of Month/WeekDay

saza

Member
Hi there,

for my program I am using the B4XDateTemplate in B4A.

In this template the month on the top right is in english language. Same goes for the weekday. I can't seem to find a way to change them to a different language or even any different term/name.

To make it a bit more clear:
In the picture below you can see that the current month is "July" and the weekdays are "Mo", "Tu", "We", ...
Is there a way to change the month to "I Don't Care" instead of "July" and the weekdays "Mo", "Di", "Mi", ...
1595191863738.png

I thought that one option could be the following code but it did not seem to work:

Private DateTemplate As B4XDateTemplate
DateTemplate.lblMonth.Text.Replace("July", "I Don't Care")

Thanks in advance.
SaZa
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
DateTemplate.lblMonth.Text.Replace("July", "I Don't Care")
This line doesn't do anything. String is immutable. You cannot change it by calling a method.

The months and days names should be based on the device locale.
You can force it with this code in Service_Create of the starter service:
B4X:
Dim jo As JavaObject
jo.InitializeStatic("java.util.Locale").RunMethod("setDefault", Array(jo.GetField("GERMAN")))
 
Upvote 0

saza

Member
Hi Erel,

it st
ill does not seem to work. Because of that I attached the code of the project.

Thank you for your help in advance.

Activity:
#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#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.

    Private Dialog As B4XDialog
    Private XUI As XUI
    Private DateTemplate As B4XDateTemplate
    Private btnDatum As B4XView
    Private Base As B4XView
    
    Private pnlLoadingIndicator As B4XView
    Private ldiLaden As B4XLoadingIndicator
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("frmAnmelden")
    
    DateTime.DateFormat = "dd.MM.yyyy"
    
    Base = Activity
    Dialog.Initialize (Base)
    DateTemplate.Initialize
    DateTemplate.MinYear = 2010
    DateTemplate.MaxYear = 2100
    
    'Montag als ersten Wochentag einstellen. Sonst wäre Sonntag der erste Wochentag.
    DateTemplate.FirstDay = 1
    
    'Farben anpassen, sodass sie zum Gesamtdesign passen!
    Dialog.Title = "Wähle das Rechnungsdatum."
    Dialog.TitleBarColor = 0xFF0A0B37 'Hintergrundfarbe der Titelzeile: dunkelblau
    Dialog.TitleBarTextColor = 0xFFFFBD59
    Dialog.ButtonsColor = 0xFF0A0B37 'Hintergrundfarbe der Buttons einstellen: dunkelblau
    Dialog.ButtonsTextColor = 0xFFFFBD59 'Farbe des Buttons einstellen: Gold
    Dialog.BackgroundColor = 0xFF0A0B37 'Hintergrundfarbe der Templates einstellen: dunkelblau
    DateTemplate.SelectedColor = 0xFFFFBD59 'Goldene Farbe von Buttons und co
    DateTemplate.DaysInMonthColor = XUI.Color_White 'Schriftfarbe der Monate weiß
    DateTemplate.DaysInWeekColor = XUI.Color_White 'Schriftfarbe der Tage weiß
    DateTemplate.lblMonth.TextColor = XUI.Color_White 'Schriftfarbe der Monatsauswahl weiß
    DateTemplate.lblYear.TextColor = XUI.Color_White 'Schriftfarbe der Jahresauswahl weiß
    For Each x As B4XView In Array(DateTemplate.btnMonthLeft, DateTemplate.btnMonthRight, DateTemplate.btnYearLeft, DateTemplate.btnYearRight)
        x.Color = XUI.Color_Transparent
    Next
    DateTemplate.lblMonth.Text.Replace("July", "I Don't Care")
    
    pnlLoadingIndicator.Visible = False
End Sub

Sub Activity_Resume
    pnlLoadingIndicator.Visible = False
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    pnlLoadingIndicator.Visible = False
End Sub

'=======================================================================================================================
'Verwenderinteraktion
'=======================================================================================================================

Sub btnDatum_Click
    'only CANCEL needed
    Wait For (Dialog.ShowTemplate(DateTemplate, "", "", "Abbrechen")) Complete (Result As Int)
    If Result = XUI.DialogResponse_Positive Then
        btnDatum.Text = DateTime.Date(DateTemplate.Date)
    End If
End Sub


Starter:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: 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 Service_Create
    'This is the program entry point.
    'This is a good place to load resources that are not specific to a single activity.
    Dim jo As JavaObject
    jo.InitializeStatic("java.util.Locale").RunMethod("setDefault", Array(jo.GetField("GERMAN")))
End Sub

Sub Service_Start (StartingIntent As Intent)
    Service.StopAutomaticForeground 'Starter service can start in the foreground state in some edge cases.
End Sub

Sub Service_TaskRemoved
    'This event will be raised when the user removes the app from the recent apps list.
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub


Best,
SaZa
 
Upvote 0

Toky Olivier

Active Member
Licensed User
Longtime User
This line doesn't do anything. String is immutable. You cannot change it by calling a method.

The months and days names should be based on the device locale.
You can force it with this code in Service_Create of the starter service:
B4X:
Dim jo As JavaObject
jo.InitializeStatic("java.util.Locale").RunMethod("setDefault", Array(jo.GetField("GERMAN")))
Hello,

I use B4XDialog too with DateTemplate but our language (Malagasy) is not yet avalailable in Android languages. Is ther a method to change MonthNames too for DateTemplate?

Thank you.
 
Upvote 0
Top