Spinner SelectedIndex Problem

thewavemaster

Member
Licensed User
Longtime User
Hi!



My App(should) Read a File and then Preselect the content in a Spinner.

Dim Text1 As String

If File.Exists(File.DirInternal,"lang.txt") Then
Text1 = File.ReadString(File.DirInternal,"lang.txt")
ToastMessageShow(Text1,True)
Spinner1.SelectedIndex = Spinner1.IndexOf(Text1)
Else
ToastMessageShow("Please select your language first!",True)
End If


The showed preselected Index or Text of the Spinner is always the same (wrong)...

The Content of the File definitly exists in the Spinner. I think im making a basic mistake because of not understanding something basic...
 

thewavemaster

Member
Licensed User
Longtime User
definitly. in my case it even doesnt work when i try to change it with e.g Spinner1.selectedindex = 3 and Spinner1.Selectindex = 4. Its always the same....!?
 
Upvote 0

thewavemaster

Member
Licensed User
Longtime User
But it only works when i put in a e.g. sub button_click.

When I Call the sub out of the activity_create it doesnt work...?!
 
Upvote 0

thewavemaster

Member
Licensed User
Longtime User
Ok...i Can post parts of it:


Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim AllLocales() As String
AllLocales = Array As String("ar", "bg", "da","de","el", "en", "es", "fi", "fr", "hr", "hu", "it", "ja", "lt", "lv", "nl", "no","pl","pt", "ro", "ru", "sk", "sl","sq", "sr", "sv", "th", "tr", "uk", "vi", "zh")
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.
Dim ImageView1 As ImageView
Dim ImageView2 As ImageView
Dim ImageView3 As ImageView
Dim ImageView4 As ImageView
Dim Label1 As Label
Dim Label2 As Label
Dim tts2 As TTS
Dim Spinner1 As Spinner
Dim ToggleButton1 As ToggleButton
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("Layout1")
If FirstTime Then
tts2.Initialize("tts2")
End If
Laden

End Sub

Sub TTS2_Ready (Success As Boolean)
If Success Then
Dim listOfSupported As List
listOfSupported.Initialize
For i = 0 To AllLocales.Length - 1
Dim s() As String
s = Regex.Split("_", AllLocales(i))
If s.Length = 1 Then
If tts2.SetLanguage(s(0), "") = True Then listOfSupported.Add(AllLocales(i))
Else
If tts2.SetLanguage(s(0), s(1)) = True Then listOfSupported.Add(AllLocales(i))
End If
Next
For i = 0 To listOfSupported.Size - 1
Spinner1.Add(listOfSupported.Get(i)) 'print to the log
Next
End If
End Sub
Sub ToggleButton1_CheckedChange(Checked As Boolean)
If ToggleButton1.Checked = True Then
File.WriteString (File.DirInternal,"lang.txt",Spinner1.SelectedItem)
StartServiceAt(speaker,DateTime.Now + 1000,True)
Else
StopService(speaker)
End If

End Sub


Sub Spinner1_ItemClick (Position As Int, Value As Object)

End Sub

Sub Laden()
Dim Text1 As String
If File.Exists(File.DirInternal,"lang.txt") Then
Text1 = File.ReadString(File.DirInternal,"lang.txt")
ToastMessageShow(Text1,True)
Spinner1.SelectedIndex = Spinner1.IndexOf(Text1)
Else
ToastMessageShow("Please select your language first!",True)
End If
End Sub
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Can't you post a zip file (IDE menu Files / Export As Zip) with a project or a simplified project that shows the problem instead of posting just a partial code so we could test it in the same conidtions as you do ?

Best regards.
 
Upvote 0

thewavemaster

Member
Licensed User
Longtime User
damn...im sorry its quite a complex project. i just dont understand why i cant change the selecteindex out of the Sub Activity_Create()?

When I put it in the Sub Button1_Click() it works.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…