Reputation: 481
I am beginner level in android. how to create multidimensional array in android at runtime.
i want to create multidimensional array of EditText box dynamically (at runtime) and all should be disables except the first one.
if any one knows about this please answer. examples will be appreciated.
this working ok..
TextView textView[][] = new TextView[2][2];
after this when i tried to assign data it throws nullpointor exception..
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
editText[i][j].setText("data");
}
}
Upvotes: 0
Views: 3051
Reputation: 481
this is the code for multidimensional array of edittext and to display it as well as to disable it...
layout = new LinearLayout(this);
layout.setOrientation(1);
layout.setLayoutParams(new ViewGroup.LayoutParams(-1, -1));
EditText editText[][] = new EditText[2][2];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 2; j++) {
editText[i][j] = new EditText(this);
editText[i][j].setText("1");
editText[i][j].setWidth(50);
layout.addView(editText[i][j]);
}
}
for (int i = 1; i < 2; i++) {
for (int j = 0; j < 2; j++) {
// editText[i][j].setEnabled(false);
editText[i][j].setClickable(false);
editText[i][j].setEnabled(false);
}
}
setContentView(layout);
Upvotes: 1