Auto change focus between two buttons periodically
<pre><code>package com.example.helloandroid;

import java.util.Timer;  
import java.util.TimerTask;  

import android.app.Activity;

import android.os.Bundle;

import android.os.Handler;

import android.util.Log;

import android.view.View;

import android.widget.Button;


public class HelloandroidActivity extends Activity {

/** Called when the activity is first created. */

Button mybtn0,mybtn1;

private Handler mhandler= new Handler();

Timer timer= new Timer();

String s=new String(" ");

int delay=0;

int period=5000;

int var=0;

@Override

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // Object o=null;
    // o.toString();
    // TextView tv = new TextView(this);
    // tv.setText("Hello Andriod");

    setContentView(R.layout.main);
    mybtn0= (Button)findViewById(R.id.number_button);
    //mybtn.requestFocus();
    mybtn0.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click
            mybtn0.clearFocus();
        }
    });
    // mybtn2= (Button)findViewById(R.id.contact_button);
    //setUpFocus();

    try
    {

    mybtn1=(Button)findViewById(R.id.contact_button);   
    //mybtn2= (Button)mybtn.focusSearch(View.FOCUS_DOWN);
    mybtn1.requestFocus();
    mybtn0.clearFocus();

    }
    catch(Exception e)
    {
            Log.e("focus change","focus failed",e);
    } 


    timer.scheduleAtFixedRate(new TimerTask(){

        public void run()
        { 

            switch(var)
            {

            case 0: mybtn0.clearFocus();
                    mybtn1.requestFocus();
                    break;

            case 1: mybtn1.clearFocus();
                    mybtn0.requestFocus();
                break;
            default: break;
            }

            var= (var+1)%2;


        }

    }, delay, period);

}
</code></pre>

<p>I have used the above code to accomplish auto change focus between two buttons using timer. but I am getting "called from wrong thread Exception".
I think it is because of timer. please someone correct this code and as well provide the sample code on how to implement this with Handler class.</p>
