我怎么能叫一个不同的XML我onResume在Android的Eclipse项目中的第二个呼叫
问题描述:
我做一个Android应用程序,我想在我的MainActivity.java使我onResume方法的计数器的来电,这样在onResume的:
I make an Android app and I want in my MainActivity.java to make a counter of my onResume method calls so that during onResume's:
1)第一次调用的setContentView(R.layout.layout1);
和
2)第二次调用的setContentView(R.layout.layout2);
据我seeked我应该做一个静态变量,将每一个onResume的号召增加文档。
According to documentation that I seeked I should make a static variable that will be increased for every onResume's call.
我怎么能实现它吗?
谢谢你在前进。
How could I implement it please? Thank you in advance.
答
也许这样的事情(粗略模板)
Perhaps something like this (rough template)
public class MainActivity {
public static int contentViewCount = 0;
public void onCreate() { //or perhaps onStart()
contentViewCount = 0;
}
public void onResume() {
if(contentViewCount == 0) {
//set first layout and increment the static counter
setContentView(R.layout.layout1);
contentViewCount++;
} else {
setContentView(R.layout.layout2);
}
}
}