我正在製作一個文字遊戲,其中每個用戶都有多個猜測,每個猜測都由多個TextView組成。到目前爲止,我的代碼讀取:android textview arrays
TextView[] guess1 = new TextView[numTextViews];
guess1[0] = (TextView) findViewById(R.id.Guess1_1);
guess1[1] = (TextView) findViewById(R.id.Guess1_2);
guess1[2] = (TextView) findViewById(R.id.Guess1_3);
guess1[3] = (TextView) findViewById(R.id.Guess1_4);
guess1[4] = (TextView) findViewById(R.id.Guess1_5);
與XML看起來像:
<TextView
android:id="@+id/Guess1_1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:gravity="center"
android:text="@string/guessChar" />...
與android:id=
改變重複。
如果我輸入TextView[] guess2
及其所有元素,我將重複自己。
- 什麼是更好的方式去做這件事?
- 以編程方式創建所有TextView是否更好?因爲它們非常相似?
你所做的事對我來說似乎很好。使用XML更好。 – Doomsknight 2013-05-03 06:55:03