我怎么能叫一个不同的XML我onResume在Android的Eclipse项目中的第二个呼叫 [英] How can I call a different xml on the second call of my onResume in Android Eclipse project

查看:101
本文介绍了我怎么能叫一个不同的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);
        }
    }
 }

这篇关于我怎么能叫一个不同的XML我onResume在Android的Eclipse项目中的第二个呼叫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆