我已經通過其他活動設置按鈕可見性問題的另一個acticty可見設置按鈕與偏好設置
代碼解釋:
首先,menu.xml
<Button
android:id="@+id/f1"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginRight="10dp"
android:background="@drawable/button1"
android:visibility="visible" />
<ImageView
android:id="@+id/f2lock"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:src="@drawable/levellocked"
android:visibility="visible" />
<Button
android:id="@+id/f2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/button2"
android:visibility="gone" />
f2
按鈕用於意圖leveltwo.class
但它仍然設置爲GONE, f2lock
is ImageView for levellocked
其次,menu.java
public class menu extends Activity {
Button f1, f2;
ImageView f2lock;
@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.famouslevel);
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");
startActivityForResult (level1, 0);
}
});
}
public void onActivityResult (int requestCode, int resultCode, Intent level1){
super.onActivityResult (requestCode, resultCode, level1);
f2=(Button)findViewById(R.id.f2);
f2lock=(ImageView)findViewById(R.id.f2lock);
switch (resultCode) {
case 2: f2.setVisibility(View.VISIBLE);
f2lock.setVisibility(View.GONE);
}
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");
startActivityForResult (level2, 0);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.splashscreen, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
下面的代碼來調用levelone.java
有結果
所以levelone.java
我把這樣的代碼
public void onClick(View v){
setResult (2);
finish();
}
});
代碼功能是發送結果( 2)到menu.class
時level.class
完成();
public void onActivityResult (int requestCode, int resultCode, Intent level1){
super.onActivityResult (requestCode, resultCode, level1);
f2=(Button)findViewById(R.id.f2);
f2lock=(ImageView)findViewById(R.id.f2lock);
switch (resultCode) {
case 2: f2.setVisibility(View.VISIBLE);
f2lock.setVisibility(View.GONE);
}
上面的代碼是從levelone.class
接收結果(2),並做case 2
功能
問題是如何使用和在殼體2設置SharedPreferences?所以F2和f2lock知名度將保存
,因爲我有嘗試SharedPreferences代碼,但沒有什麼發生,F2鍵還是走了,f2lock ImageView的仍可見
我的意思是這樣的:
就像一場遊戲當用戶做了1級水平,從而將2解鎖
但在這裏我做一個1級的
嘿,那裏。我可以幫助你解決這個問題,但是有點困惑你究竟在問什麼。這可能是我成爲一隻愚蠢的鵝,但仍然 - 請在意見中解釋,或者對你的問題進行解答,以便我能夠給予你適當的迴應。 – Sipty
有了更多的抽象和更少的代碼引用,我應該補充一下。 – Sipty
代碼我的意思是像一個正常的遊戲兄弟,當1級完成2級解鎖 – RichFounders