Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7488535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T14:56:42+00:00 2026-05-29T14:56:42+00:00

I’ve a very strange problem, i try to disable a toggle button for just

  • 0

I’ve a very strange problem,
i try to disable a toggle button for just a sec in order to make impossible for people in my application to spamclick it.

my toggleButton has this listener :

videoToggleListener = new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                switchVideoSource();
                switchBetweenSources.setEnabled(false);

                freezeToggle.schedule(new TimerTask(){

                    @Override
                    public void run() {

                        switchBetweenSources.setEnabled(false);
                        switchBetweenSources.setEnabled(true);

                    }

                }, 1000);


            }
        };

my application doesn’t force close on setEnabled(false) but do force close on setEnabled(true).

any idea ?

my log cat :

02-10 13:45:30.500: E/AndroidRuntime(7285): FATAL EXCEPTION: Timer-0
02-10 13:45:30.500: E/AndroidRuntime(7285): android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.view.ViewRoot.checkThread(ViewRoot.java:2932)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.view.ViewRoot.invalidateChild(ViewRoot.java:642)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.view.ViewRoot.invalidateChildInParent(ViewRoot.java:668)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.view.ViewGroup.invalidateChild(ViewGroup.java:2511)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.view.View.invalidate(View.java:5255)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.widget.TextView.invalidateDrawable(TextView.java:3916)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.graphics.drawable.LayerDrawable.invalidateDrawable(LayerDrawable.java:298)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.graphics.drawable.Drawable.invalidateSelf(Drawable.java:300)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.graphics.drawable.DrawableContainer.selectDrawable(DrawableContainer.java:227)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.graphics.drawable.StateListDrawable.onStateChange(StateListDrawable.java:99)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.graphics.drawable.Drawable.setState(Drawable.java:400)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.graphics.drawable.LayerDrawable.onStateChange(LayerDrawable.java:409)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.graphics.drawable.Drawable.setState(Drawable.java:400)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.view.View.drawableStateChanged(View.java:7374)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.widget.TextView.drawableStateChanged(TextView.java:2312)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.widget.CompoundButton.drawableStateChanged(CompoundButton.java:265)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.widget.ToggleButton.drawableStateChanged(ToggleButton.java:143)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.view.View.refreshDrawableState(View.java:7388)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at android.view.View.setEnabled(View.java:3147)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at fr.partisocialiste.psa.activity.VideosGridActivity$1$1.run(VideosGridActivity.java:101)
02-10 13:45:30.500: E/AndroidRuntime(7285):     at java.util.Timer$TimerImpl.run(Timer.java:284)
02-10 13:45:32.804: I/Process(7285): Sending signal. PID: 7285 SIG: 9

EDIT :

i’ve change my listener this way :

videoToggleListener = new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView,
                    boolean isChecked) {
                switchVideoSource();
                switchBetweenSources.setEnabled(false);

                freezeToggle.schedule(new TimerTask(){

                    @Override
                    public void run() {
                        runOnUiThread(new Runnable(){

                            @Override
                            public void run() {
                                switchBetweenSources.setEnabled(true);

                            }                               
                        });                         
                    }                   
                }, 2000);
            }
        };

Thanks everybody, you’re awsome =) !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T14:56:43+00:00Added an answer on May 29, 2026 at 2:56 pm

    Obviously the problem is that you try to alter a View from a non-UI thread. If you say that you don’t get this exception on the first line inside the TimerTask, just in the second, this may be because your ToggleButton is already disabled, and this does not alter the View.

    To change the state of the View from other Thread thant the UI Thread you should use runOnUiThread().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a jquery bug and I've been looking for hours now, I can't
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.