Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
QuizApp 4.1
package jp.codeforfun.quizapp;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
private TextView countLabel, questionLabel;
private Button answerBtn1, answerBtn2, answerBtn3, answerBtn4;
private String rightAnswer;
private int rightAnswerCount;
private int quizCount = 1;
ArrayList<ArrayList<String>> quizArray = new ArrayList<>();
String[][] quizData = {
// {"都道府県名", "正解", "選択肢1", "選択肢2", "選択肢3"}
{"北海道", "札幌市", "長崎市", "福島市", "前橋市"},
{"青森県", "青森市", "広島市", "甲府市", "岡山市"},
{"岩手県", "盛岡市","大分市", "秋田市", "福岡市"},
{"宮城県", "仙台市", "水戸市", "岐阜市", "福井市"},
{"秋田県", "秋田市","横浜市", "鳥取市", "仙台市"},
{"山形県", "山形市","青森市", "山口市", "奈良市"},
{"福島県", "福島市", "盛岡市", "新宿区", "京都市"},
{"茨城県", "水戸市", "金沢市", "名古屋市", "奈良市"},
{"栃木県", "宇都宮市", "札幌市", "岡山市", "奈良市"},
{"群馬県", "前橋市", "福岡市", "松江市", "福井市"},
protected void onCreate(Bundle savedInstanceState) {
countLabel = findViewById(;
questionLabel = findViewById(;
answerBtn1 = findViewById(;
answerBtn2 = findViewById(;
answerBtn3 = findViewById(;
answerBtn4 = findViewById(;
// 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に追加する
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment