android - ImageButton Based On If Condition -
i have implemented imagebutton
changes images based on 3 conditions, 1 of condition set follows:
if (local().equals(remote)) { ib.setimageresource(r.drawable.sync_green); } else { ib.setimageresource(r.drawable.sync_red); }
this works after few seconds app crashes following log:
06-20 11:58:27.734: e/androidruntime(2278): fatal exception: thread-160 06-20 11:58:27.734: e/androidruntime(2278): process: com.twostarii.asyncdownload, pid: 2278 06-20 11:58:27.734: e/androidruntime(2278): android.view.viewrootimpl$calledfromwrongthreadexception: original thread created view hierarchy can touch views. 06-20 11:58:27.734: e/androidruntime(2278): @ android.view.viewrootimpl.checkthread(viewrootimpl.java:6247) 06-20 11:58:27.734: e/androidruntime(2278): @ android.view.viewrootimpl.invalidatechildinparent(viewrootimpl.java:902) 06-20 11:58:27.734: e/androidruntime(2278): @ android.view.viewgroup.invalidatechild(viewgroup.java:4637) 06-20 11:58:27.734: e/androidruntime(2278): @ android.view.view.invalidateinternal(view.java:11690) 06-20 11:58:27.734: e/androidruntime(2278): @ android.view.view.invalidate(view.java:11654) 06-20 11:58:27.734: e/androidruntime(2278): @ android.view.view.invalidate(view.java:11638) 06-20 11:58:27.734: e/androidruntime(2278): @ android.widget.imageview.setimageresource(imageview.java:402) 06-20 11:58:27.734: e/androidruntime(2278): @ com.twostarii.asyncdownload.androiddownloadfilebyprogressbaractivity$1.run(androiddownloadfilebyprogressbaractivity.java:172)
you can't change drawable because not on main ui thread.
try doing this:
runonuithread(new runnable() { @override public void run() { // code here run on ui thread } });
Comments
Post a Comment