views:

112

answers:

3

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);
        }

    }

}

A: 

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

Roflcoptr
How I can do that ?
SultanSh
The documentation is really clear, but I'll edit my answer.
Roflcoptr
Thanx I'll try it.
SultanSh
Still not working sorry
SultanSh
What means not working? Is there an error? And can you show the code?
Roflcoptr
I can't figureout what updateYourLayout(); is and how to do it
SultanSh
super.onCreate(savedInstanceState); TimerTask bla = new YourTask(); Timer timer = new Timer(); setContentView(R.layout.s); timer.schedule(bla,1000);
SultanSh
package com.rdwt;import java.util.TimerTask;public class YourTask extends TimerTask { public void run() { updateYourLayout(); } }
SultanSh
and then it asked me to create the methode updateYourLayout();
SultanSh
yes thats a method you should implement somewhere in your code and then do there what you want to do.
Roflcoptr
How? and what should that method do and how it can update layout
SultanSh
Ok I read again your question and I think what your really looking for is a splashscreen. This (http://www.anddev.org/simple_splash_screen-t811.html) very simple tutorial shows exactly how to do it. Just follow the steps there.
Roflcoptr
Thanx alot my friend. I really appreciate your efforts to help me :)
SultanSh
A: 

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

Pentium10
Thanx but still I want more helpfull answer
SultanSh
A: 

// 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();  
andy_spoo
Thanx I'll try it
SultanSh