Reputation: 37
I Want to make the my Button go invisible or gone a few seconds after the activity is created. Using a thread gave me this error
The Error is in here :
android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
Then I tried using a Handler, this gave me this error:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.LstSearch/com.LstSearch.BasicMusicView}: java.lang.NullPointerException
So then I tried using runOnUiThread(). If I execute this in onCreate(), the activity takes the amount of time as I have specified in the thread, and the image will go invisible after that much time. But when the activity starts after 3 seconds, the image has already turned itself invisible. I think have found the Solution as a new entry they are not allowing me to answer me question so i am editing here
handler=new Handler();
Runnable r=new Runnable()
{ public void run()
{change image }
};
handler.postDelayed(r, 1000);
Cheers!!
Upvotes: 0
Views: 808
Reputation: 29121
you need to call the invisibility function on the UIThread(), you can though views only in UIThread.
user runonUIthread()
method.
Upvotes: 1