让我们尝试使其易于理解。
例如,我得到了“ Page1”和“ Page2”以及“ Page3”。
好。我在“ Page2”上创建了一个初始屏幕,因此用户可以在特定时间(5秒)内看到“ Page2”。它会自动将他定向到“ Page3”,我还在“ Page2”上添加了两个按钮,因此用户可以单击“ Button1”,从而更快地转到“ Page3”。或转到“第1页”的“ Button2”
好吧,我做到了所有正确的。
但是,如果“ Page2”处于打开状态,并且用户没有触摸任何东西,它将带他进入“ Page3”。.我的问题是,用户可以触摸任何“ Button1”或“ Button2”,这会将他定向到“ Page3”,并且如果他触摸了“ Button2”并转到“ Page1”(在“ Page2”上启动屏幕的时间限制到期后,它将自动将他从“ Page1”定向到“ Page3”
请帮忙。
我的代码是
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.content.Intent;
import android.view.View.OnClickListener;
import android.widget.Button;
public class StartGame extends Activity {
// ===========================================================
// Fields
// ===========================================================
private final int SPLASH_DISPLAY_LENGHT = 3000;
// ===========================================================
// "Constructors"
// ===========================================================
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.startgame);
/* New Handler to start the Menu-Activity
* and close this Splash-Screen after some seconds.*/
new Handler().postDelayed(new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(StartGame.this,Fail.class);
StartGame.this.startActivity(mainIntent);
StartGame.this.finish();
}
}, SPLASH_DISPLAY_LENGHT);
请帮助,谢谢。
瓦希德
编辑:
抱歉,我是一个初学者,我真的不知道如何创建变量,
请您与我分享一些知识并向我展示源代码。
如果变量表示按钮。,那已经在那里,但我没有
最佳答案
如果您的活动2已通过单击按钮停止,则需要取消postDelayed呼叫。
因此,首先您需要从可运行对象和处理程序创建变量。
然后按下任一按钮,您将可以呼叫:
myHandler.removeCallbacks(myRunnable);
如果不再需要它,它将阻止它触发。
编辑以适合OP的初学者资料:
myRunnable = new Runnable(){
@Override
public void run() {
/* Create an Intent that will start the Menu-Activity. */
Intent mainIntent = new Intent(StartGame.this,Fail.class);
StartGame.this.startActivity(mainIntent);
StartGame.this.finish();
}
}
myHandler = new Handler();
myHandler.postDelayed(myRunnable, SPLASH_DISPLAY_LENGHT);