Android Question Way to enable one button

Douglas Farias

Expert
Licensed User
Longtime User
have one way to
start layout with my button1.enabled = false

and enable this button on a sub ?

B4X:
sub botao
button1.enabled = true
end sub

i need start my button enabled = false on layout
later if i have a update on my db the button go enabled = true automatic

its possible?

this is the error when i try enable my button on sub
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
 

stevel05

Expert
Licensed User
Longtime User
It's the same thing you had before, you need to use the Threads RunOnGuiThread method to call the sub botao
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
this sub check updates and call the sub ativabotoes to enable buttons

B4X:
Sub ProcessHTML(Html As String)
    Dim dica As String
    Dim lala As StringFunctions
    lala.Initialize
   
    If Html.Contains("/dica") = True Then
    dica = lala.MidExtract(Html,"<dica>","</dica>")
    eventoatual = lala.MidExtract(Html,"<eventoid>","</eventoid>")
    teste = estado&cidade&eventoatual
    kv.PutSimple("EventoID",eventoatual)
   
    If dica.StartsWith("Dica 1") = True Then
    kv.PutSimple("Dica1-"&teste,dica)
    ativabotoes
   
    Else If dica.StartsWith("Dica 2") = True Then
    kv.PutSimple("Dica2-"&teste,dica)
    ativabotoes
   
    Else If dica.StartsWith("Dica 3") = True Then
    kv.PutSimple("Dica3-"&teste,dica)
    ativabotoes
   
    Else If dica.StartsWith("Dica 4") = True Then
    kv.PutSimple("Dica4-"&teste,dica)
    ativabotoes
   
    Else If dica.StartsWith("Dica 5") = True Then
    kv.PutSimple("Dica5-"&teste,dica)
    ativabotoes
   
    Else If dica.StartsWith("Dica 6") = True Then
    kv.PutSimple("Dica6-"&teste,dica)
    ativabotoes
   
    Else If dica.StartsWith("Dica 7") = True Then
    kv.PutSimple("Dica7-"&teste,dica)
    ativabotoes
   
    Else If dica.StartsWith("Dica 8") = True Then
    kv.PutSimple("Dica8-"&teste,dica)
    ativabotoes
   
    Else If dica.StartsWith("Dica 9") = True Then
    kv.PutSimple("Dica9-"&teste,dica)
    ativabotoes
   
    Else If dica.StartsWith("Dica 10") = True Then
    kv.PutSimple("Dica10-"&teste,dica)
    ativabotoes

    Else
    End If
    End If
End Sub


B4X:
Sub ativabotoes

If kv.ContainsKey("Dica1-"&teste) = True Then
Button1.Enabled = True
End If

If kv.ContainsKey("Dica2-"&teste) = True Then
Button2.Enabled = True
End If

If kv.ContainsKey("Dica3-"&teste) = True Then
Button3.Enabled = True
End If

If kv.ContainsKey("Dica4-"&teste) = True Then
Button4.Enabled = True
End If

If kv.ContainsKey("Dica5-"&teste) = True Then
Button5.Enabled = True
End If

If kv.ContainsKey("Dica6-"&teste) = True Then
Button6.Enabled = True
End If

If kv.ContainsKey("Dica7-"&teste) = True Then
Button7.Enabled = True
End If

If kv.ContainsKey("Dica8-"&teste) = True Then
Button8.Enabled = True
End If

If kv.ContainsKey("Dica9-"&teste) = True Then
Button9.Enabled = True
End If

If kv.ContainsKey("Dica10-"&teste) = True Then
Button10.Enabled = True
End If

End Sub
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
ok i tryed but what the params?

Thread1.RunOnGuiThread(sub, params())

in this case how to call the sub ativabotoes ?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Use Null as the params if there aren't any.

B4X:
Thread1.RunOnGuiThread("ativabotoes" , Null)
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
ok

B4X:
Sub Process_Globals
Dim Thread1 As Thread
End Sub

Sub Activity_Create(FirstTime As Boolean)
Thread1.Initialise("Thread1")
End Sub



Sub ativabotoes

If kv.ContainsKey("Dica1-"&teste) = True Then
Button1.Enabled = True
End If

If kv.ContainsKey("Dica2-"&teste) = True Then
Button2.Enabled = True
End If

If kv.ContainsKey("Dica3-"&teste) = True Then
Button3.Enabled = True
End If

If kv.ContainsKey("Dica4-"&teste) = True Then
Button4.Enabled = True
End If

If kv.ContainsKey("Dica5-"&teste) = True Then
Button5.Enabled = True
End If

If kv.ContainsKey("Dica6-"&teste) = True Then
Button6.Enabled = True
End If

If kv.ContainsKey("Dica7-"&teste) = True Then
Button7.Enabled = True
End If

If kv.ContainsKey("Dica8-"&teste) = True Then
Button8.Enabled = True
End If

If kv.ContainsKey("Dica9-"&teste) = True Then
Button9.Enabled = True
End If

If kv.ContainsKey("Dica10-"&teste) = True Then
Button10.Enabled = True
End If

End Sub


Sub ProcessHTML(Html As String)
    Dim dica As String 
    Dim lala As StringFunctions
    lala.Initialize
   
    If Html.Contains("/dica") = True Then
    dica = lala.MidExtract(Html,"<dica>","</dica>")
    eventoatual = lala.MidExtract(Html,"<eventoid>","</eventoid>")
    teste = estado&cidade&eventoatual
    kv.PutSimple("EventoID",eventoatual)
   
    If dica.StartsWith("Dica 1") = True Then
    kv.PutSimple("Dica1-"&teste,dica)
    Thread1.RunOnGuiThread("ativabotoes" , Null)
   
    Else If dica.StartsWith("Dica 2") = True Then
    kv.PutSimple("Dica2-"&teste,dica)
    Thread1.RunOnGuiThread("ativabotoes" , Null)
   
    Else If dica.StartsWith("Dica 3") = True Then
    kv.PutSimple("Dica3-"&teste,dica)
    Thread1.RunOnGuiThread("ativabotoes" , Null)
   
    Else If dica.StartsWith("Dica 4") = True Then
    kv.PutSimple("Dica4-"&teste,dica)
    Thread1.RunOnGuiThread("ativabotoes" , Null)
   
    Else If dica.StartsWith("Dica 5") = True Then
    kv.PutSimple("Dica5-"&teste,dica)
    Thread1.RunOnGuiThread("ativabotoes" , Null)
   
    Else If dica.StartsWith("Dica 6") = True Then
    kv.PutSimple("Dica6-"&teste,dica)
    Thread1.RunOnGuiThread("ativabotoes" , Null)
   
    Else If dica.StartsWith("Dica 7") = True Then
    kv.PutSimple("Dica7-"&teste,dica)
    Thread1.RunOnGuiThread("ativabotoes" , Null)
   
    Else If dica.StartsWith("Dica 8") = True Then
    kv.PutSimple("Dica8-"&teste,dica)
    Thread1.RunOnGuiThread("ativabotoes" , Null)
   
    Else If dica.StartsWith("Dica 9") = True Then
    kv.PutSimple("Dica9-"&teste,dica)
    Thread1.RunOnGuiThread("ativabotoes" , Null)
   
    Else If dica.StartsWith("Dica 10") = True Then
    kv.PutSimple("Dica10-"&teste,dica)
    Thread1.RunOnGuiThread("ativabotoes" , Null)

    Else
    End If
    End If
End Sub


ERROR LOG
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
a sory i forgot initialise on my code
now works fine ty stevel05
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
very strange
on release mode buttons enable work
on debug too
on obfuscated nop
obfuscated don enable the buttons
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If you are calling subs with any of the string paramters, CallSub, CallSubDelayed or RunOnGuiThread in obfuscated mode, the sub names need to contain an underscore '_' or they will be obfuscated, and the calls wont find them.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…