1
我正在製作一個android應用程序,作爲一個項目,它將用戶的輸入視爲輸入no。然後它動態地創建文本框,以便在下一個意圖中顯示矩陣的行和列。現在我需要這些值進行進一步的計算,如反轉,轉置,加法,減法等。我需要這些值到b存儲在一個二維數組,這樣我可以用它easily.please幫助,,並thankx 這裏是我的代碼如何從動態創建的editText框中獲取值,並將輸入的值保存到二維數組中
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
int rows = getIntent().getIntExtra("rows",3);
int cols = getIntent().getIntExtra("cols",3);
matrix = (LinearLayout) findViewById(R.id.matrix);
matrix.removeAllViews();
List<EditText> allEds = new ArrayList<EditText>();//thisline
for (int a = 1; a <= rows; a++)
{
LinearLayout layout = new LinearLayout(Main2Activity.this);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.setLayoutParams(new LinearLayout.LayoutParams
(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT,1));
for (int b = 1; b <= cols; b++)
{
EditText text = new EditText(Main2Activity.this);
//text.setBackgroundColor(Color.GRAY);
allEds.add(text);//thisline
text.setHint("**");
text.setKeyListener(new DigitsKeyListener());
text.setHintTextColor(Color.BLACK);
int iD = 1;
//noinspection ResourceType
text.setId(iD);
text.setLayoutParams(new LinearLayout.LayoutParams
(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1));
//text.setText((j + 1) + " ");
text.setTextColor(Color.RED);
layout.addView(text);
}
matrix.addView(layout);
}
String[] strings = new String[allEds.size()];
for(int a=1; a <= allEds.size();a++)
{
for (int b = 1; b <= cols; b++)
{
strings[b] = allEds.get(b).getText().toString();
}
}