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 ?

Code: Copy
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.
 
It's the same thing you had before, you need to use the Threads RunOnGuiThread method to call the sub botao
 
Upvote 0
this sub check updates and call the sub ativabotoes to enable buttons

Code: Copy
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


Code: Copy
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
ok i tryed but what the params? o.O

Thread1.RunOnGuiThread(sub, params())

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

Code: Copy
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
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=achou.ganhou.vallow/.main }
no extras
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
[]
** Activity (main) Pause, UserClosed = false **
** Activity (telaprincipal) Create, isFirst = true **
** Activity (telaprincipal) Resume **
Error occurred on line: 0 (keyvaluestore)
java.lang.NullPointerException
at anywheresoftware.b4a.agraham.threading.Threading.RunOnGuiThread(Threading.java:108)
at achou.ganhou.vallow.telaprincipal._processhtml(telaprincipal.java:1257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.ShellBA$1.run(ShellBA.java:66)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=achou.ganhou.vallow/.main }
no extras
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
[]
** Activity (main) Pause, UserClosed = false **
** Activity (telaprincipal) Create, isFirst = true **
** Activity (telaprincipal) Resume **
Error occurred on line: 0 (keyvaluestore)
java.lang.NullPointerException
at anywheresoftware.b4a.agraham.threading.Threading.RunOnGuiThread(Threading.java:108)
at achou.ganhou.vallow.telaprincipal._processhtml(telaprincipal.java:1257)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.ShellBA$1.run(ShellBA.java:66)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
 
Upvote 0
a sory i forgot initialise on my code
now works fine ty stevel05
 
Upvote 0
very strange
on release mode buttons enable work
on debug too
on obfuscated nop o.O
obfuscated don enable the buttons
 
Upvote 0
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
Back
Top