表行指定的小孩已经有一个父。您必须先对孩子的父母打电话removeView() [英] Table row The specified child already has a parent. You must call removeView() on the child's parent first
本文介绍了表行指定的小孩已经有一个父。您必须先对孩子的父母打电话removeView()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无法在表格布局务实添加表行。我在这里创建一个视图滚动的水平和垂直方向都并查看类似于表并没有问题,添加的TableRow
Unable to add table row pragmatically in table layout. I am here creation a view scrollable horizontally and vertically both and view similar to table and there is problem in adding TableRow
/*
* reportLayout is tablelayout by findViewById
* i am setting view inside Fragment
*/
public void redrawReport(){
reportLayout.removeAllViews();
int count=0;
for(SaleReportModel model:Detailist.getReportItems()){
TableRow headerRow= new TableRow(getActivity());
headerRow.removeAllViews();
//Error Caused here in this line
headerRow.addView(getTextView(model.getPrdcode(), false,count*4),count);
headerRow.addView(getTextView(model.getSubtype(), false,count*4+1),count);
headerRow.addView(getTextView(""+model.getDispatchQty(), false,count*4+2),count);
headerRow.addView(getTextView(""+model.getDispatchvalue(), false,count*4+3),count);
reportLayout.addView(headerRow,new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,TableLayout.LayoutParams.WRAP_CONTENT));
count+=1;
}
}
public TextView getTextView(String data,boolean isHeader,int id){
TextView textView= new TextView(getActivity());
textView.setLayoutParams( new LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,TableLayout.LayoutParams.WRAP_CONTENT));
textView.setText(data);
textView.setId(id);
textView.setGravity(Gravity.CENTER);
//textView.setTextColor(Color.BLACK);
return mDateFrom;
}
错误日志:
11-09 12:04:40.299: E/AndroidRuntime(19569): FATAL EXCEPTION: main
11-09 12:04:40.299: E/AndroidRuntime(19569): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
11-09 12:04:40.299: E/AndroidRuntime(19569): at android.view.ViewGroup.addViewInner(ViewGroup.java:3739)
11-09 12:04:40.299: E/AndroidRuntime(19569): at android.view.ViewGroup.addView(ViewGroup.java:3610)
11-09 12:04:40.299: E/AndroidRuntime(19569): at android.view.ViewGroup.addView(ViewGroup.java:3555)
11-09 12:04:40.299: E/AndroidRuntime(19569): at com.kiss.erp.view.fragment.SalesFragment.redrawReport(SalesFragment.java:254)
11-09 12:04:40.299: E/AndroidRuntime(19569): at com.kiss.erp.view.fragment.SalesFragment.showdetail(SalesFragment.java:196)
11-09 12:04:40.299: E/AndroidRuntime(19569): at com.kiss.erp.view.fragment.SalesFragment.onClick(SalesFragment.java:110)
请帮忙。
但愿这引起TableLayout父所以这里查看XML。
May it caused by parent of TableLayout so view xml here.
<ScrollView
android:id="@+id/layoutReport"
android:layout_height="match_parent"
android:scrollbars="horizontal|vertical"
android:layout_width="match_parent"
android:layout_marginTop="5dip"
android:scrollbarStyle="outsideInset"
android:fillViewport="true">
<HorizontalScrollView
android:id="@+id/horizontalView"
android:layout_height="wrap_content"
android:scrollbars="horizontal|vertical"
android:layout_width="wrap_content"
android:layout_marginTop="5dip">
<TableLayout
android:id="@+id/tlGridTable"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</TableLayout>
</HorizontalScrollView>
先谢谢了。
推荐答案
在方法 getTextView
,你回来 mDateForm
而不是的TextView
。
由于 mDateForm
已经有一个父视图,你得到一个例外。
正确实施应该是这样的:
In the method getTextView
, you're returning mDateForm
instead of textView
.
Since mDateForm
already has a parent view, you're getting an Exception.
Correct implementation should be like this:
public TextView getTextView(String data,boolean isHeader,int id){
TextView textView= new TextView(getActivity());
textView.setLayoutParams( new LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,TableLayout.LayoutParams.WRAP_CONTENT));
textView.setText(data);
textView.setId(id);
textView.setGravity(Gravity.CENTER);
//textView.setTextColor(Color.BLACK);
return textView;
}
这篇关于表行指定的小孩已经有一个父。您必须先对孩子的父母打电话removeView()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文