1
我是android開發新手。我注意到了一些類似的問題,但他們都沒有真正回答我的問題,以至於我可以弄明白,否則他們依賴於折舊的功能。Android:根據用戶輸入動態創建editText的矩陣?
到目前爲止,我創建了我的主課程。我想開到一個畫面,讓用戶輸入他們想要減少
public class MainActivity extends AppCompatActivity {
public int numberOfRows;
public int numberOfColumns;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void setRows(View v3) {
EditText editTextRow = (EditText) findViewById(R.id.editText2);
if ("".equals(editTextRow.getText())) {
}
else {
numberOfRows = Integer.parseInt(editTextRow.getText().toString());
}
}
public void setColumns(View v2) {
EditText editTextCol = (EditText) findViewById(R.id.editText3);
if ("".equals(editTextCol.getText())) {
numberOfRows = Integer.parseInt(editTextCol.getText().toString());
}
}
public void reduce(View view){
if(numberOfRows != 0 && numberOfColumns != 0) {
}
else {
Intent intent = new Intent(this, ReduceMatrix.class);
Bundle bundle = new Bundle();
bundle.putInt("rows", numberOfRows);
bundle.putInt("cols", numberOfColumns);
intent.putExtras(bundle);
startActivity(intent);
}
}
}
我有想出下一個活動,在這裏我想麻煩動態矩陣的行和列的長度兩個數字創建一個editText矩陣...
public class ReduceMatrix extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_reduce_matrix);
Intent passedIntent = getIntent();
Bundle extras = passedIntent.getExtras();
int rowNum = extras.getInt("rows");
int colNum = extras.getInt("cols");
任何人都可以解釋如何去做到這一點?我正在考慮某種循環,但我對android佈局非常困難。我應該使用tableLayout嗎?或gridview?每當我有類似的東西
layout = new LinearLayout(this);
它告訴我,我的限定詞必須在表達式?
謝謝。我的xml文件應該是什麼樣子?我應該有一個空的gridLayout嗎?目前這個編譯,但運行應用程序時沒有任何東西可見 – JVandeve
@JVandeve你不需要一個xml文件,因爲這段代碼做的是以編程方式創建佈局。所以,你不需要爲佈局創建一個xml文件。那麼,你能告訴我更多關於「什麼都看不見」的嗎?你的意思是沒有顯示活動(看起來像應用程序沒有啓動)?如果是,那麼你需要在'AndroidManifest.xml'文件中爲你的活動添加一個意圖過濾器。 –