Android Question Button1.enabled = true error

Douglas Farias

Expert
Licensed User
Longtime User
i m want to simple enable my button and i have this error

my button is made on design

my layout is initializated normal
no problems

on design my button is enabled = false

i m trying this to enable
B4X:
If kv.ContainsKey("Dica1-"&estado&cidade&eventoatual) = True Then
Button1.Enabled = True
End If

but give a error o_O
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.


** Activity (main) Resume **
Installing file.
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:achou.ganhou.vallow
** 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 **
Billing service connected.
Checking for in-app billing 3 support.
In-app billing version 3 supported for achou.ganhou.vallow
Subscriptions AVAILABLE.
Starting async operation: refresh inventory
Querying owned items, item type: inapp
Package name: achou.ganhou.vallow
Calling getPurchases with continuation token: null
Owned items response: 0
Continuation token: null
Querying SKU details.
queryPrices: nothing to do because there are no SKUs.
Querying owned items, item type: subs
Package name: achou.ganhou.vallow
Calling getPurchases with continuation token: null
Owned items response: 0
Continuation token: null
Querying SKU details.
queryPrices: nothing to do because there are no SKUs.
Ending async operation: refresh inventory
Dica 2: O objeto onde se encontra o dinheiro fica a céu aberto, e não dentro de 4 paredes e um teto.
** Activity (telaprincipal) Pause, UserClosed = true **
** Activity (selecionacidade) Create, isFirst = true **
** Activity (selecionacidade) Resume **
[{"Estado":"Rio Grande do Sul"},{"Estado":"Acre"}]
[{"Cidade":"S\u00e3o Leopoldo"},{"Cidade":"Porto Alegre"},{"Cidade":"Canoas"},{"Cidade":"Novo Hamburgo"}]
** Activity (selecionacidade) Pause, UserClosed = true **
** Activity (telaprincipal) Create, isFirst = false **
** Activity (telaprincipal) Resume **
android.view.ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at android.view.ViewRootImpl.checkThread(ViewRootImpl.java:6818)
at android.view.ViewRootImpl.invalidateChildInParent(ViewRootImpl.java:1112)
at android.view.ViewGroup.invalidateChild(ViewGroup.java:4484)
at android.view.View.invalidate(View.java:11339)
at android.widget.TextView.invalidateDrawable(TextView.java:5647)
at android.graphics.drawable.DrawableContainer.invalidateDrawable(DrawableContainer.java:250)
at android.graphics.drawable.Drawable.invalidateSelf(Drawable.java:375)
at android.graphics.drawable.Drawable.setVisible(Drawable.java:586)
at android.graphics.drawable.DrawableContainer.selectDrawable(DrawableContainer.java:307)
at android.graphics.drawable.StateListDrawable.onStateChange(StateListDrawable.java:106)
at android.graphics.drawable.Drawable.setState(Drawable.java:502)
at android.view.View.drawableStateChanged(View.java:15511)
at android.widget.TextView.drawableStateChanged(TextView.java:3997)
at android.view.View.refreshDrawableState(View.java:15525)
at android.view.View.setEnabled(View.java:6125)
at android.widget.TextView.setEnabled(TextView.java:1810)
at anywheresoftware.b4a.objects.ViewWrapper.setEnabled(ViewWrapper.java:217)
at achou.ganhou.vallow.telaprincipal._ativabotoes(telaprincipal.java:598)
at achou.ganhou.vallow.telaprincipal._processhtml(telaprincipal.java:1693)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:162)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:158)
at uk.co.martinpearman.b4a.webviewextras.WebViewExtras$1B4AJavascriptInterface.CallSub(WebViewExtras.java:71)
at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
at android.webkit.BrowserFrame.stringByEvaluatingJavaScriptFromString(Native Method)
at android.webkit.BrowserFrame.loadUrl(BrowserFrame.java:320)
at android.webkit.WebViewCore.loadUrl(WebViewCore.java:3338)
at android.webkit.WebViewCore.access$2300(WebViewCore.java:77)
at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1943)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:1093)
at java.lang.Thread.run(Thread.java:841)
 

Attachments

  • Sem título.png
    Sem título.png
    217.8 KB · Views: 182

stevel05

Expert
Licensed User
Longtime User
It looks like you are running in a thread, you can't touch the views directly. You need to set up a subroutine to do the work then call that with the threads RunOnGuiThread method.
 
Last edited:
Upvote 0
Top