2

我想创建edittext的动态网格,但它给了我一个IllegalStateException:

特定的孩子已经有一个孩子,你必须先打电话removeView() 给孩子父母。

这是我的代码:

for (int x = 0; x < no_of_rows; x++)
{
    ll = new LinearLayout(this.getApplicationContext());
    ll.setLayoutParams(new LinearLayout.LayoutParams(
        LinearLayout.LayoutParams.FILL_PARENT,
        LinearLayout.LayoutParams.WRAP_CONTENT));
    ll.setOrientation(0);

    for(int y = 0; y < no_of_columns; y++){
        LinearLayout(this.getApplicationContext());
        this.edittext2.add(new EditText(this.getApplicationContext()));
        this.edittext2.get(y).setId(y);
        this.edittext2.get(y).setLayoutParams(new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.FILL_PARENT
                    ,LinearLayout.LayoutParams.WRAP_CONTENT));
        this.edittext2.get(y).setMaxLines(1);
        this.edittext2.get(y).setText("Something");
        ll.addView(this.edittext2.get(y));
    }
    tlayout.addView(ll);
}
4

0 回答 0