私は動的にテーブルの行を作ってから、イメージビューとテキストビューを動的に追加するアンドロイドアプリを作成しています。Android:java.lang.IllegalStateException:指定された子がすでに親を持っています。子の親で最初にremoveView()を呼び出す必要があります。
ar1= new JSONArray(children.toString());
for(int mn=0;mn<ar1.length();mn++){
value=ar1.getString(mn);
TableRow tr = new TableRow(HomePageWithPhoneIsOfflineDialog.this);
tr.setBackgroundColor(Color.WHITE);
tr.setId(100+mn);
tr.setMinimumHeight(60);
tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
TextView child= new TextView(HomePageWithPhoneIsOfflineDialog.this);
child.setId(200+mn);
child.setHeight(50);
child.setGravity(Gravity.CENTER);
child.setTextColor(Color.BLACK);
System.out.println(value);
child.setText(value);
System.out.println("adding iv");
tr.addView(iv,0);
System.out.println("adding child");
tr.addView(child);
System.out.println("adding table row");
table.addView(tr, new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT));
}
を誰がどのようにこの問題を解決するために教えてもらえます: それは私がそれのために以下のコードを使用しています最初の行を追加し、次の例外に
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
を与えます。
* *ここで*はその例外をスローしますか? –
ここで位置を指定する... tr.addView(子);常に同じではありません。 – Noby