I have main.xml and main.class that has two buttons named : Level 1 and Level 2
each button has a function to open another class
level1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
// TODO Auto-generated method stub
Intent i =new Intent(getApplicationContext(),level1.class);
startActivity(i);
level2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v){
// TODO Auto-generated method stub
Intent i =new Intent(getApplicationContext(),level2.class);
startActivity(i);
}
});
but the condition is level 2 button are locked but i dont know how to make a locked button, The first thing i want to ask is how to make a locked button
and to unlock level 2 button , level1.class event must completed. in level1.class has code like this
public class level1 extends Activity implements OnClickListener {
int gamelifes=6, index=0, score=0;
String [] answer ={"the answer"};
lifes =(TextView)findViewById(R.id.lifestext);
lifes.setTextColor(Color.RED);
lifes.setText(String.valueOf(gamelifes));
buttonanswer = (Button)findViewById(R.id.buttonanswer);
buttonanswer.setOnClickListener(this);
good =(ImageView)findViewById(R.id.youwin);
good.setOnClickListener(this);
buttonfinish = (Button)findViewById(R.id.finish);
buttonfinish.setOnClickListener(this);
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
edittext=(EditText)findViewById(R.id.editText);
if(v==buttonanswer) {
String abc =edittext.getText().toString();
if(abc.equalsIgnoreCase(answer[index]))
{
good.setVisibility(View.VISIBLE);
buttonfinish.setVisibility(View.VISIBLE);
score++;
}
else
{
gamelifes--;
}
buttonfinish.setOnClickListener(new View.OnClickListener() {
public void onClick(View v){
finish();
}
});
}
when the answer is right there will be show up some image and a button.
and score++;
if the answer is correct and gamelifes--;
if wrong.
my next question is how to make score
and gamelifes
values send to level2.class whereas the conditions when buttonfinish
Click will finish();
and return to Main.class and unlock the level 2 button in main.class
then how to make a sharedpreference setting to save the unlock button?