Skip to content

Instantly share code, notes, and snippets.

@codingwithsara
Created October 15, 2018 04:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingwithsara/6e51c9afe72d6ad03bb5796977031e60 to your computer and use it in GitHub Desktop.
Save codingwithsara/6e51c9afe72d6ad03bb5796977031e60 to your computer and use it in GitHub Desktop.
第3回
package com.codingwithsara.quizapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private TextView countLabel;
private TextView questionLabel;
private Button answerBtn1;
private Button answerBtn2;
private Button answerBtn3;
private Button answerBtn4;
private String rightAnswer;
private int rightAnswerCount = 0;
private int quizCount = 1;
ArrayList<ArrayList<String>> quizArray = new ArrayList<>();
String quizData[][] = {
// {"都道府県名", "正解", "選択肢1", "選択肢2", "選択肢3"}
{"北海道", "札幌市", "長崎市", "福島市", "前橋市"},
{"青森県", "青森市", "広島市", "甲府市", "岡山市"},
{"岩手県", "盛岡市","大分市", "秋田市", "福岡市"},
{"宮城県", "仙台市", "水戸市", "岐阜市", "福井市"},
{"秋田県", "秋田市","横浜市", "鳥取市", "仙台市"},
{"山形県", "山形市","青森市", "山口市", "奈良市"},
{"福島県", "福島市", "盛岡市", "新宿区", "京都市"},
{"茨城県", "水戸市", "金沢市", "名古屋市", "奈良市"},
{"栃木県", "宇都宮市", "札幌市", "岡山市", "奈良市"},
{"群馬県", "前橋市", "福岡市", "松江市", "福井市"},
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
countLabel = findViewById(R.id.countLabel);
questionLabel = findViewById(R.id.questionLabel);
answerBtn1 = findViewById(R.id.answerBtn1);
answerBtn2 = findViewById(R.id.answerBtn2);
answerBtn3 = findViewById(R.id.answerBtn3);
answerBtn4 = findViewById(R.id.answerBtn4);
// クイズデータquizDataからクイズ出題用のquizArrayを作成する
for (int i = 0; i < quizData.length; i++) {
// 新しいArrayListを準備
ArrayList<String> tmpArray = new ArrayList<>();
// クイズデータを追加
tmpArray.add(quizData[i][0]); // 都道府県名
tmpArray.add(quizData[i][1]); // 正解
tmpArray.add(quizData[i][2]); // 選択肢1
tmpArray.add(quizData[i][3]); // 選択肢2
tmpArray.add(quizData[i][4]); // 選択肢3
// tmpArrayをquizArrayに追加する
quizArray.add(tmpArray);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment