簡単な四択クイズを作成しています。
その中で,正解したときにToastで「正解」と表示させていたのですが
このままではつまらないと感じ,正解したときには「正解」という画像を表示させたいと考えています。
ですが,.javaで表示させる方法が調べても分からず困っています。
どのようにしたらできるのでしょうか??
また,プログラムを簡略化できるのであれば教えてもらいたいです。
どうか、よろしくお願いします。
下記にプログラムを載せておきます。
public class Kuroneko_no_with01 extends AppCompatActivity implements View.OnClickListener{ /*ボタン*/ private Button Choice01; private Button Choice02; private Button Choice03; private Button Choice04; /*選択肢*/ private String[] Choice = {"ラグビー", "テニス", "バレー", "サッカー"}; /*解答*/ private String[] answer = {"","","",""}; /*制限時間*/ private ProgressBar mProgress3; private Handler mHandler = new Handler(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_kuroneko_no_with01); /*ボタン*/ Choice01 = (Button) findViewById(R.id.choice01); Choice01.setOnClickListener(this); Choice02 = (Button) findViewById(R.id.choice02); Choice02.setOnClickListener(this); Choice03 = (Button) findViewById(R.id.choice03); Choice03.setOnClickListener(this); Choice04 = (Button) findViewById(R.id.choice04); Choice04.setOnClickListener(this); /*乱数のListを作成*/ List<Integer> ran = new ArrayList<>(); for(int i = 0; i < Choice.length; i++) { int tmp =(int)(Math.random()*4); ran.add(i,tmp); if(i >= 1) { for (int j = 0; j < i; j++) { if(ran.get(j) == tmp){ i--; ran.remove(j); } } } } /*ボタンの名前*/ Choice01.setText(Choice[ran.get(0)]); Choice02.setText(Choice[ran.get(1)]); Choice03.setText(Choice[ran.get(2)]); Choice04.setText(Choice[ran.get(3)]); /*制限時間の設定*/ mProgress3 = (ProgressBar) findViewById(R.id.progress3); mProgress3.setMax(20); mProgress3.setProgress(0); new Thread(new Runnable() { @Override public void run() { while(mProgress3.getProgress() < 20) { mHandler.post(new Runnable() { @Override public void run() { mProgress3.incrementProgressBy(1); } }); try { Thread.sleep(1000); } catch (InterruptedException e) { } } finish(); } }).start(); } @Override public void onClick(View v) { answer[0] = Choice01.getText().toString(); answer[1] = Choice02.getText().toString(); answer[2] = Choice03.getText().toString(); answer[3] = Choice04.getText().toString(); /**/ if(v == Choice01){ if(answer[0] == "ラグビー") { **ここに「正解」を表示させるプログラムを書きたい** // インテントのインスタンス生成 Intent intent = new Intent(this, Kuroneko_no_with01.class); /*遷移開始*/ startActivity(intent); }else{ Toast.makeText(this, "不正解", Toast.LENGTH_LONG).show(); } }else if(v == Choice02){ if(answer[1] == "ラグビー") { // インテントのインスタンス生成 Intent intent = new Intent(this, Kuroneko_no_with01.class); /*遷移開始*/ startActivity(intent); }else{ Toast.makeText(this, "不正解", Toast.LENGTH_LONG).show(); } }else if(v == Choice03){ if(answer[2] == "ラグビー") { // インテントのインスタンス生成 Intent intent = new Intent(this, Kuroneko_no_with01.class); /*遷移開始*/ startActivity(intent); }else{ Toast.makeText(this, "不正解", Toast.LENGTH_LONG).show(); } }else if(v == Choice04){ if(answer[3] == "ラグビー") { // インテントのインスタンス生成 Intent intent = new Intent(this, Kuroneko_no_with01.class); /*遷移開始*/ startActivity(intent); }else{ Toast.makeText(this, "不正解", Toast.LENGTH_LONG).show(); } } } }
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/15 16:46
2016/12/16 01:06