我想遍历EditTexts的GridView,以便我可以从每个EditTexts获取值。为了测试它,我尝试了这个代码:
EditText element;
String matrix_value;
//Iterate through GridView
int gridSize = gridView.getChildCount();
for(int i=0; i<gridSize; i++)
{
element = (EditText) gridView.getChildAt(i);
matrix_value = element.getText().toString();
}
但我在element = (EditText) gridView.getChildAt(i);
收到了投射错误
如何将每个EditText分配到element
?
答案 0 :(得分:0)
你尝试过这样的事吗?
EditText element;
String matrix_value;
//Iterate through GridView
int gridSize = gridView.getChildCount();
for(int i=0; i<gridSize; i++) {
if(gridView.getChildAt(i) instanceof EditText) {
element = (EditText) gridView.getChildAt(i);
matrix_value = element.getText().toString();
}
}