我對Android Studio還相當新,我想通過創建一個帶有所需行和列的GridLayout並用EditTexts填充它來測試某些東西。然而,我遇到了一個問題,我不知道在EditText構造函數中作爲參數放置什麼。 這裏是下面的Java代碼:要在Android Studio中的EditText構造函數的參數中放入什麼?
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//The numbers WILL vary but this is just a test
int rows = 3;
int columns = 4;
GridLayout gd = (GridLayout) findViewById(R.id.grid1);
gd.setRowCount(rows);
gd.setColumnCount(columns);
EditText edt;
for(int r = 0; r < rows; r++)
{
for(int c = 0; c < columns; c++)
{
//What to put in the parameters in this code below?
edt = new EditText();
gd.addView(edt);
}
}
}
這裏是XML:
<GridLayout
android:id="@+id/grid1"
android:layout_width="368dp"
android:layout_height="495dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp">
</GridLayout>
我看了看構造函數的EditText和發現需要這方面,但我怎麼把在那裏?如果這不是正確的做法,請告訴我正確的方法。
非常感謝!我忘了那個 –