【android studio】 配列を変換して画面に表示したい
テトリスを作っていまして、枠を表示したいのですがうまくいきません。
表示結果が□が一つだけ表示されることから、setTextにより「 」と「□」順次入れ替わっているだけと推察していますが、改善方法がわかりません。どうかご教示のほどよろしくお願い致します。
該当のソースコード
xml
1<?xml version="1.0" encoding="utf-8"?> 2<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:app="http://schemas.android.com/apk/res-auto" 4 xmlns:tools="http://schemas.android.com/tools" 5 android:layout_width="match_parent" 6 android:layout_height="match_parent" 7 tools:context=".MainActivity"> 8 9 <TextView 10 android:id="@+id/puzzle" 11 android:layout_width="210dp" 12 android:layout_height="400dp" 13 android:background="@drawable/border" 14 android:textSize="30dp" 15 app:layout_constraintBottom_toTopOf="@+id/left" 16 app:layout_constraintLeft_toLeftOf="parent" 17 app:layout_constraintRight_toLeftOf="@+id/next" 18 app:layout_constraintTop_toTopOf="parent" />
java
1import android.support.v7.app.AppCompatActivity; 2import android.os.Bundle; 3import android.widget.TextView; 4 5public class MainActivity extends AppCompatActivity { 6 7 @Override 8 protected void onCreate(Bundle savedInstanceState) { 9 super.onCreate(savedInstanceState); 10 setContentView(R.layout.activity_main); 11 12 int field[][] = 13 { // 0 1 2 3 4 5 6 7 8 9 10 11 14 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //0 15 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //1 16 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //2 17 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //3 18 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //4 19 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //5 20 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //6 21 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //7 22 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //8 23 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //9 24 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //10 25 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //11 26 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //12 27 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //13 28 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //14 29 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //15 30 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //16 31 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //17 32 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //18 33 {1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}, //19 34 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1} //20 35 }; 36 37 TextView textView = findViewById(R.id.puzzle); 38 39 for (int i = 0; i <= 20; i++) { 40 for (int j = 0; j <= 11; j++) { 41 if (field[i][j] == 1) { 42 textView.setText("□"); 43 44 } else { 45 textView.setText(" "); 46 } 47 } 48 } 49 } 50}
試したこと
ここに問題に対して試したことを記載してください。
補足情報(FW/ツールのバージョンなど)
ここにより詳細な情報を記載してください。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/07/27 00:31