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 3485722
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:56:30+00:00 2026-05-18T10:56:30+00:00

I’ve checked the other questions asked here and didn’t succeed in implementing the solutions.

  • 0

I’ve checked the other questions asked here and didn’t succeed in implementing the solutions. My application uses controls, not drawing on the canvas. Basically this sums up my issue: –

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    btn1 = (ToggleButton) findViewById(R.id.btn1);
    btn2 = (ToggleButton) findViewById(R.id.btn2);
    btn3 = (ToggleButton) findViewById(R.id.btn2);
    btn4 = (ToggleButton) findViewById(R.id.btn4);
    btn5 = (ToggleButton) findViewById(R.id.btn5);
    btn6 = (ToggleButton) findViewById(R.id.btn6);
    btn7 = (ToggleButton) findViewById(R.id.btn7);
 //blah blah blah
    btn1.requestFocus();
    wait(100);
    btn2.requestFocus();
    wait(100);
    btn3.requestFocus();
    wait(100);
    btn3.setChecked(true);
    wait(100);
    btn4.requestFocus();
    wait(100);
    btn4.setChecked(true);
    wait(100);
    btn5.requestFocus();
    wait(100);
    btn6.requestFocus();
    wait(100);
    btn6.setChecked(true);
    wait(100);
    btn7.requestFocus();
    wait(100);
 //etc
}

The point being the computer animates the moving to a the buttons and checking them so the user can see what it is doing. So, my issue is, what goes in my wait() method that will pause for 100ms and also update the screen, and the focus? Any help really appreciated, cheers Jonathan.

Solution applies, thanks Andrew 🙂

int timerCounterInterval = 0;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    final ToggleButton btn1 = (ToggleButton) findViewById(R.id.btn1);
    final ToggleButton btn2 = (ToggleButton) findViewById(R.id.btn2);
// more btns
    timerCounterInterval = 0; //reset, for each pass of automation
    setFocus(btn1);
    setFocus(btn2);
    setChecked(btn2);
// tidy up
    timerCounterInterval++;
    new Handler().postDelayed(new Runnable() { 
        public void run() {
            btn2.clearFocus(); //whatever button that had the focus last
            }
    }, 100*(timerCounterInterval));
// etc - note any code from here will execute *before* the above timer
}   

public void setFocus(final ToggleButton btn) {
    timerCounterInterval++;
    new Handler().postDelayed(new Runnable() { 
        public void run() {
            btn.setFocusableInTouchMode(true); //eww, messy i know
            btn.requestFocus();
            btn.setFocusableInTouchMode(false); 
        } 
    }, 100*timerCounterInterval);
}

public void setChecked(final ToggleButton btn) {
    timerCounterInterval++;
    new Handler().postDelayed(new Runnable() { 
        public void run() {
            btn.setChecked(true);
        } 
    }, 100*timerCounterInterval);
}

Hope this helps other people!

  • 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-18T10:56:31+00:00Added an answer on May 18, 2026 at 10:56 am

    I highly suggest you look into the Handle object and in particular the postDelayed method. That way you can keep everything on the UI thread while not causing the thread to actually be tied up in an animate method. This also keeps the Activity from giving that dreaded this-application-is-not-responding message.

    In fact, simply wrapping your calls to the control’s setters in a runnable and passing them to postDelayed should be enough to update the GUI controls.

    [Update]
    As an example per your comments you might try something like this. I haven’t actually tested this but I think the idea is still there…

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final ToggleButton btn1 = (ToggleButton) findViewById(R.id.btn1);
        final ToggleButton btn2 = (ToggleButton) findViewById(R.id.btn2);
        // more btns
    
        Handler handler = new Handler();
    
        /* tell the handler run these bits after 1 sec, 2 sec, 3 sec, ect... */
        handler.postDelayed(new Runnable() { void run () { btn1.requestFocus(); } }, 1000);
        handler.postDelayed(new Runnable() { void run () { btn2.requestFocus(); } }, 2000);
        handler.postDelayed(new Runnable() { void run () { btn2.setChecked(true); } }, 3000);
    }
    
    • 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
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.