I have a problem with setting the Visibility button using another action
Code designation:
First 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" />
Button
f2 used for the intent leveltwo.class , but it is still set to GONE, f2lock is an ImageView for levellocked
Secondly, 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){
the following code to call levelone.java with the result
so in levelone.java i will put code like this
public void onClick(View v){ setResult (2); finish(); } });
the code function sends the result (2) to menu.class when level.class ends ();
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); }
the above code should get the result (2) from levelone.class and execute case 2 function
The question is, how to use and set SharedPreferences in case 2? therefore, the visibility of f2 and f2lock will be preserved
because I tried the SharedPreferences code but nothing happens, the f2 button is still GONE and the f2lock imageview is still VISIBLE
i means the following:
Like a game, when the user completed level 1, so that level 2 will be unlocked
but here I do the VISIDLE button when level 1 is running