开发者

How can I make the android program display a layout and then wai a few sec. and the display another layout?

Hi guys I just want the program to display the layout main0 and stay for a few secounds then display layout main1 like the programs we see in any phone where an image or layout show up at the start of the program and then fade.

/**the main activity */

public class rdwt extends Activity implements OnClickListener{

Button b1;
Button b2;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main0);
    //Here
    setContentView(R.layout.main1);

    b1= (Button)findViewById(R.id.Button01);
    b2= (Button)findViewById(R.id.Button02);
    b1.setOnClickListener(this);
    b2.setOnClickListener(this);


}

    public void onClick(View v) {
        if (v==this.b1){
            Intent callwrite = new Intent(this开发者_运维技巧, wto.class);              
            startActivity(callwrite);
        }

        if(v==this.b2){
            Intent callread = new Intent(this, rfr.class);               
            startActivity(callread);
        }

    }

}


You need to read a technical article about Updating the UI from a Timer


I think there are particularly two different approaches.

1) use a android.os.Handler and send a delayed message

2) use a timer and a timer task to update your layout after a specific amount of time

Code example:

TimerTask bla = new YourTask();
Timer timer = new Timer();
timer.schedule(bla, 1000);

And your class YourTask:

public class YourTask extends TimerTask {

   public void run() {
     updateYourLayout();
   }

}

Edit: However I think you're looking for a splashscreen. This simple tutorial explains how to do it: http://www.anddev.org/simple_splash_screen-t811.html


// Place the following line in your code.

   timer(3500); // Waits 3.5 seconds before moving on to the next activity.



   public void timer(int counter){ 
        new Handler().postDelayed(new Runnable(){
            @Override
            // counter is in milliseconds.
            public void run() {             
                Intent mainIntent = new Intent(THISCLASSNAME.this,CLASSNAMETOJUMPTO.class);
                startActivity(mainIntent);
                finish();  
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜