请与StaticClass按钮可见,并将其保存 [英] Make button visible with StaticClass and Save it

查看:182
本文介绍了请与StaticClass按钮可见,并将其保存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还是弄糊涂了与我的朋友这给替代节省除了共享preferences StaticClass code,已经3天我试着学会了code和要求,但仍有小问题,一个code

I still got confused with StaticClass code which given from my friend to alternative save besides Shared Preferences, already 3 days I tried learned the code and asked but there is still a little problem with a code

这是最新以下code在我的 selectlevel.class ,我已经完善

this is the latest following code in my selectlevel.class that i have perfected

public class selectlevel extends Activity {

    Button f1, f2, f3;
    ImageView f2lock, f3lock;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.selectlevel);


       f1=(Button)findViewById(R.id.f1);
       f1.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v){
                    // TODO Auto-generated method stub
                    Intent level1 = new Intent ();
                    level1.setClassName ("com.example.game", "com.example.game.levelone");
                    startActivity (level1);              
                }             
            }); 

        f2=(Button)findViewById(R.id.f2);
        f2lock=(ImageView)findViewById(R.id.f2lock);
        f2.setOnClickListener(new View.OnClickListener() {

             @Override
             public void onClick(View v){
               // TODO Auto-generated method stub
                Intent level2 = new Intent ();
                level2.setClassName ("com.example.game", "com.example.game.leveltwo");
                startActivity (level2);              
                }                       
          });
            updateLevels();
    }

    static class PlayerProgress {

        private static int progress = 0;

        public static void updateProgress(int levelNumber) {
            progress = levelNumber;
        }  

        public static int getPlayerProgress() {
            return progress;
        }
    }

    public void updateLevels() {
        int progress = PlayerProgress.getPlayerProgress();


    switch(progress) {
        case 1:
            f2.setVisibility(View.VISIBLE);
            f2lock.setVisibility(View.GONE);
            break;
        case 2:

            break;

        // You can expand this to as many levels you'd like.
    }
  }

和我有使用这在我的 levelone.class 发送更新进度1

and i had use this in my levelone.class to send update progress to 1

button1.setOnClickListener(new View.OnClickListener() {

          public void onClick(View v){
              selectlevel.PlayerProgress.updateProgress(1);
              finish(); 

levelone.class 完成,F2键还是走了,f2lock仍可见

but when levelone.class finish, f2 button still GONE and f2lock still VISIBLE

输入图像的描述在这里

没有什么变化 selectlevel.class

我不知道它可以是可见这样,仍然可见,如果本场比赛再开,因为按钮知名度保存

i wonder it can be visible like this and still visible if the game re-open because the button visibility is saved

输入图像的描述在这里

谁能帮我解决我的code的一个问题?或给另一个code作为解决方案,解释一下吗?

can anyone help me to fix a problem in my code? or give explain with another code as solution?

推荐答案

尝试调用 updateLevels()功能也在你的onClick funtion是这样的:

try to call the updateLevels() function also in your onClick funtion like this:

button1.setOnClickListener(new View.OnClickListener() {

      public void onClick(View v){
          selectlevel.PlayerProgress.updateProgress(1);
          selectlevel.PlayerProgress.updateLevels();
          finish(); 
}

这篇关于请与StaticClass按钮可见,并将其保存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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