LogoQuiz ゲームでは、正解を入力すると答えが表示され、アクティビティがフリーンします。その画面に戻るたびに、同じものが表示されます。それはどのように行われますか?誰でも例を挙げてもらえますか?
public class Activity3 extends Activity implements OnClickListener {
private Button Hint1;
private Button Hint2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity3);
Hint1 = (Button) findViewById(R.id.Hint1);
Hint2 = (Button) findViewById(R.id.Hint2);
Hint1.setOnClickListener(this);
Hint2.setOnClickListener(this);
Hint2.setEnabled(false);
final EditText input = (EditText) findViewById(R.id.answer);
final TextView display = (TextView) findViewById(R.id.response);
input.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER)) {
String check = input.getText().toString().replace(" ","");
if(check.equalsIgnoreCase("good")){
display.setText("correct");
input.setEnabled(false);
} else{
display.setText("Wrong");
}
return true;
}
return false;}
});
}
@Override
public void onClick(View view) {
switch(view.getId()){
case R.id.Hint1:
showOneButtonDialog();
break;
case R.id.Hint2:
showTwoButtonDialog();
break;
}}
private void showOneButtonDialog()
{
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
dialogBuilder.setTitle(" Hint 1 ");
Hint2.setEnabled(true);
dialogBuilder.setMessage(" This is your Hint1");
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
}
private void showTwoButtonDialog()
{
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
dialogBuilder.setTitle(" Hint 2 ");
dialogBuilder.setMessage("This is your Hint2 ");
AlertDialog alertDialog = dialogBuilder.create();
alertDialog.show();
}
}