我还是弄糊涂了与我的朋友这给替代节省除了共享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按钮可见,并将其保存
发布评论