Android Question Change control Text??

ilan

Expert
Licensed User
Longtime User
Hi

if i want to change the control text like button1.text to "b1" i do it like this
button1.text = "b1"

if i have now 10000 controls how could i do it short??

is it possible to get it from an excel file?
i have an excel file that in

col0 = type of the control
col1 = name ov the control
col2 = text of control (english)
col3 = text of control (german)
col4 = text of control (russian)

like this i want to make my app multilanguage
and if you cahnge the language it will get all control text from the excel file

i post a code how it should be, and a pic of my excel file maybe someone can help me

B4X:
Sub multilanguage

Dim workbook1 As ReadableWorkbook
Dim moviesSheet As ReadableSheet
workbook1.Initialize(File.DirAssets, "lang.xls")
moviesSheet = workbook1.GetSheet(0)

Dim col As Int

language = "English"'************ changeable

If language = "English" Then
col = 2
Else If language = "Deutsch" Then
col = 3
Else If language = "Russian" Then
col = 4
End If


Dim lanbutton As Button
Dim lanlabel As Label
Dim lanradio As RadioButton
Dim lancheck As CheckBox

For i = 2 To 1000
If moviesSheet.GetCellValue(0, i) = "Button" Then
lanbutton = moviesSheet.GetCellValue(1, i)
lanbutton.Text = moviesSheet.GetCellValue(col, i)
Else If moviesSheet.GetCellValue(0, i) = "Label" Then
 
lanlabel = moviesSheet.GetCellValue(1, i)
lanlabel.Text = moviesSheet.GetCellValue(col, i)
Else If moviesSheet.GetCellValue(0, i) = "RadioButton" Then
 
lanradio = moviesSheet.GetCellValue(1, i)
lanradio.Text = moviesSheet.GetCellValue(col, i)
Else If moviesSheet.GetCellValue(0, i) = "CheckBox " Then
 
lancheck = moviesSheet.GetCellValue(1, i)
lancheck.Text = moviesSheet.GetCellValue(col, i)
End If

Next


'day.Text = moviesSheet.GetCellValue(col, 2)
'txtl1.Text = moviesSheet.GetCellValue(col, 3)
'txtl2.Text = moviesSheet.GetCellValue(col, 4)
'txtl3.Text = moviesSheet.GetCellValue(col, 5)
'txtl4.Text = moviesSheet.GetCellValue(col, 6)
'txtl5.Text = moviesSheet.GetCellValue(col, 7)
'txtl6.Text = moviesSheet.GetCellValue(col, 8)
'txtl7.Text = moviesSheet.GetCellValue(col, 9)
'txtl8.Text = moviesSheet.GetCellValue(col, 10)
'txtl9.Text = moviesSheet.GetCellValue(col, 11)
'txtl10.Text = moviesSheet.GetCellValue(col, 12)
'txtl11.Text = moviesSheet.GetCellValue(col, 13)
'txtl12.Text = moviesSheet.GetCellValue(col, 14)
'txtl13.Text = moviesSheet.GetCellValue(col, 15)
'txtl14.Text = moviesSheet.GetCellValue(col, 16)
'txtl15.Text = moviesSheet.GetCellValue(col, 17)
'txtl16.Text = moviesSheet.GetCellValue(col, 18)
'txtl17.Text = moviesSheet.GetCellValue(col, 19)
'txtl18.Text = moviesSheet.GetCellValue(col, 20)
'txtl19.Text = moviesSheet.GetCellValue(col, 21)
'txtl20.Text = moviesSheet.GetCellValue(col, 22)



End Sub
 

Attachments

  • excel1.png
    excel1.png
    131.4 KB · Views: 289

klaus

Expert
Licensed User
Longtime User
I'm not sure that this is the easiest way to do it.
I think that it would be easier to have one text file for each language instead of an Excel file.
But, that's just my opinion.
You could have a look at NotePad where I use this concept.
But as told before that's my vision.
You may have a look at AHLocation, I use it in NotePad, only to detect the current language of the device but the library has mor features.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
how do you mean have a text file for each language?

i think it doesnot matter if its a excel file or txt file

my problem is something different

i know the control name

but how can i change the control.text via string

like:

button1.text = "b1"

now with string

"button" & "1".text = "b1"

i know this is not possible but maybe in a nother way
thatswhy i create a excel file where the control name and type is given

now i just to need to get the control name and change his text

we can take for this example also a listview
if i have a list with all my controls names and i want now to change text of those controls

the first list item is button1

now how can i do it?

dim b as button

b = list1.get(0)
b.text = "b1"

????????????
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Well, I gave you my solution, but of course there are others.
"button" & "1".text = "b1" is not possible so you need to find something else.
In your approch, to change the texts you need to read one column of the Excel file and do whatever you want with it and set it's content to the different views, which is not the easiest way.
That's why I proposed my solution, but it's only a suggestion.
I have used this for a long time even in Windows programs without any problem.
Depending on where you save the text files a user could even change one for his own language, but in your case the Excel file must be modified.
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
sorry klau but i dont understand you

1.) what do i have to save to the text file and how do i change my controls text?

2.) now if i would like to do it in my way, how can i call a control via "string"
if i know the control name let say the control name is "button1"

how can i change his text?
i try but its not working

dim b as button

b = "button1"
b.text = "b1"

this is what i get: "error: inconvertible types"

required: Button
found: String
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
ok klaus now i understand but your solution is good maybe for 20 views but not fo 1000

i cannot write every view

button1.text = main.text(0)...

i want a shorter solution

thatswhy i tried to do it with excel file

is there a way to change a view text like this?:

dim b as button

b = "button1"
b.text = "b1"
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
dim b as button
b = "button1"
b.text = "b1"
Unfortunately no.

You could try to use Arrays for the views or at leat a part of them but this will be even more complicated.
Are you sure you have 1000 views !?
How do you manage them ?
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
i have maybe more

if there is no way i will do it like this

B4X:
Sub multilanguage

Dim workbook1 As ReadableWorkbook
Dim moviesSheet As ReadableSheet
workbook1.Initialize(File.DirAssets, "lang.xls")
moviesSheet = workbook1.GetSheet(0)

Dim col As Int


If language = "English" Then
col = 2
Else If language = "Deutsch" Then
col = 3
Else If language = "Russian" Then
col = 4
Else
language = "English 
col = 2
End If


lanbutton.Initialize("")
lanlabel.Initialize("")
lanradio.Initialize("")
lancheck.Initialize("")
 
For i = 2 To 10

If moviesSheet.GetCellValue(0, i) = "Button" Then
lang1 = moviesSheet.GetCellValue(1, i)
callviewsbuttons
lanbutton.Text = moviesSheet.GetCellValue(col, i)
Else If moviesSheet.GetCellValue(0, i) = "Label" Then

lang2 = moviesSheet.GetCellValue(1, i)
callviewslabels
lanlabel.Text = moviesSheet.GetCellValue(col, i)
Else If moviesSheet.GetCellValue(0, i) = "RadioButton" Then

lang3 = moviesSheet.GetCellValue(1, i)
callviewsradiobuttons
lanradio.Text = moviesSheet.GetCellValue(col, i)
Else If moviesSheet.GetCellValue(0, i) = "CheckBox" Then

lang4 = moviesSheet.GetCellValue(1, i)
callviewscheckbox
lancheck.Text = moviesSheet.GetCellValue(col, i)
End If

Next
'


End Sub

Sub callviewsbuttons

If lang1 = "day" Then lanbutton = day
If lang1 = "delsh" Then lanbutton = delsh
If lang1 = "candelsh" Then lanbutton = candelsh
If lang1 = "dateselectmonth" Then lanbutton = dateselectmonth
If lang1 = "dateselectweek" Then lanbutton = dateselectweek
If lang1 = "dateselectmonth" Then lanbutton = dateselectmonth
If lang1 = "manual" Then lanbutton = manual
If lang1 = "dateselectb1" Then lanbutton = dateselectb1
If lang1 = "clockin" Then lanbutton = clockin
If lang1 = "clockpause" Then lanbutton = clockpause
If lang1 = "admobpfullbb" Then lanbutton = admobpfullbb
If lang1 = "shedulecancel" Then lanbutton = shedulecancel
If lang1 = "shedulesave" Then lanbutton = shedulesave
If lang1 = "mailpincancel" Then lanbutton = mailpincancel
If lang1 = "mailpinsend" Then lanbutton = mailpinsend
If lang1 = "sheduleinputcancel" Then lanbutton = sheduleinputcancel
If lang1 = "sheduleinputsave" Then lanbutton = sheduleinputsave
If lang1 = "spinfoclose" Then lanbutton = spinfoclose
If lang1 = "spinfoback" Then lanbutton = spinfoback
If lang1 = "Button3" Then lanbutton = Button3
If lang1 = "Button4" Then lanbutton = Button4
If lang1 = "Button2" Then lanbutton = Button2
If lang1 = "Button1" Then lanbutton = Button1

End Sub

but this is a lot of work :(
 
Last edited:
Upvote 0
Top