Android 动态创建的表行未显示在视图中
可能重复:Android 动态创建的表行未显示在视图中,android,Android,可能重复: 代码如下: DtoCbpOutcome[] outcomes = cbp.Outcomes; Log.d(_logTag, "# of outcomes: " + Integer.toString(outcomes.length)); TableLayout tl = (TableLayout) findViewById(R.id.tbl_cbp_outcomes); for (int i = 0; i < outcomes.length; i++) { // Te
代码如下:
DtoCbpOutcome[] outcomes = cbp.Outcomes;
Log.d(_logTag, "# of outcomes: " + Integer.toString(outcomes.length));
TableLayout tl = (TableLayout) findViewById(R.id.tbl_cbp_outcomes);
for (int i = 0; i < outcomes.length; i++) {
// Text Views:
// public String Description;
TableRow tr = new TableRow(appCtx);
tr.setLayoutParams(tbl_lay_parms);
// Row Count
TextView row_num = new TextView(appCtx);
temp_string = Integer.toString(i + 1);
row_num.setText(temp_string);
row_num.setLayoutParams(lay_parms);
tr.addView(row_num);
// Description
TextView desc = new TextView(appCtx);
temp_string = outcomes[i].Description;
desc.setText(temp_string);
desc.setLayoutParams(lay_parms);
tr.addView(desc);
tl.addView(tr, tbl_lay_parms);
}
但是该行没有显示在布局视图(activity\u business\u plan.xml)中
我做错了什么
谢谢
更新1
从日志中:#结果:5,由结果生成。长度
更新2
完整的布局xml:
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/green_nature_header"
android:padding="3dp"
android:text="@string/label_project_relationships"
android:textColor="@color/White"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_cbp_rel_global_priorities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="@string/double_dash" />
<TextView
android:id="@+id/tv_cbp_related_regional_priority_strategies"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="@string/double_dash" />
<TextView
android:id="@+id/tv_cbp_related_whole_system_priorities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="@string/double_dash" />
<TextView
android:id="@+id/tv_cbp_related_demonstration_priorities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="@string/double_dash" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/green_nature_header"
android:padding="3dp"
android:text="@string/label_vision_statement"
android:textColor="@color/White"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_cbp_vision_statement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="@string/double_dash" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green_nature_header"
android:padding="3dp"
android:text="@string/label_outcomes"
android:textColor="@color/White"
android:textStyle="bold" />
<TableLayout
android:id="@+id/tbl_cbp_outcomes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="5dp" >
</TableLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green_nature_header"
android:padding="3dp"
android:text="@string/label_strategies"
android:textColor="@color/White"
android:textStyle="bold" />
<TableLayout
android:id="@+id/tbl_cbp_strategies"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="5dp" >
</TableLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green_nature_header"
android:padding="3dp"
android:text="@string/label_intermediate_results"
android:textColor="@color/White"
android:textStyle="bold" />
<TableLayout
android:id="@+id/tbl_cbp_intermediate_results"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="5dp" >
</TableLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green_nature_header"
android:padding="3dp"
android:text="@string/label_activities"
android:textColor="@color/White"
android:textStyle="bold" />
<TableLayout
android:id="@+id/tbl_cbp_activities"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="5dp" >
</TableLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/green_nature_header"
android:padding="3dp"
android:text="@string/label_risks"
android:textColor="@color/White"
android:textStyle="bold" />
<TableLayout
android:id="@+id/tbl_cbp_risks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="5dp" >
</TableLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/green_nature_header"
android:padding="3dp"
android:text="@string/label_keywords"
android:textColor="@color/White"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_cbp_keywords"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="@string/double_dash" />
<TextView
android:id="@+id/tv_cbp_modified"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="3dp"
android:text="@string/double_dash"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</ScrollView>
我不知道是不是这样,但是:
您是否在tl.addView(tr,tbl_lay_parms)中使用“TableLayout.LayoutParams”
以及tr.setLayoutParams(tbl_lay_parms)中的“TableRow.LayoutParams”
我觉得不一样,请检查一下
致以最诚挚的问候这看起来不错。发布保存表格的XML以及什么是结果。长度(大于0
)?我已经为表格添加了XML。此外,结果长度产生5。我手动检查了结果的数量。我想查看包含TableLayout的布局。@Saifudin我检查了那篇文章,但结果没有解决我的问题。@Sam我添加了xml。谢谢
TableLayout (R.id.tbl_cbp_outcomes)
TableRow (tr)
TextView (row_num)
TextView (desc)
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/green_nature_header"
android:padding="3dp"
android:text="@string/label_project_relationships"
android:textColor="@color/White"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_cbp_rel_global_priorities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="@string/double_dash" />
<TextView
android:id="@+id/tv_cbp_related_regional_priority_strategies"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="@string/double_dash" />
<TextView
android:id="@+id/tv_cbp_related_whole_system_priorities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="@string/double_dash" />
<TextView
android:id="@+id/tv_cbp_related_demonstration_priorities"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="@string/double_dash" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/green_nature_header"
android:padding="3dp"
android:text="@string/label_vision_statement"
android:textColor="@color/White"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_cbp_vision_statement"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="@string/double_dash" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green_nature_header"
android:padding="3dp"
android:text="@string/label_outcomes"
android:textColor="@color/White"
android:textStyle="bold" />
<TableLayout
android:id="@+id/tbl_cbp_outcomes"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="5dp" >
</TableLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green_nature_header"
android:padding="3dp"
android:text="@string/label_strategies"
android:textColor="@color/White"
android:textStyle="bold" />
<TableLayout
android:id="@+id/tbl_cbp_strategies"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="5dp" >
</TableLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green_nature_header"
android:padding="3dp"
android:text="@string/label_intermediate_results"
android:textColor="@color/White"
android:textStyle="bold" />
<TableLayout
android:id="@+id/tbl_cbp_intermediate_results"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="5dp" >
</TableLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/green_nature_header"
android:padding="3dp"
android:text="@string/label_activities"
android:textColor="@color/White"
android:textStyle="bold" />
<TableLayout
android:id="@+id/tbl_cbp_activities"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="5dp" >
</TableLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/green_nature_header"
android:padding="3dp"
android:text="@string/label_risks"
android:textColor="@color/White"
android:textStyle="bold" />
<TableLayout
android:id="@+id/tbl_cbp_risks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingBottom="5dp" >
</TableLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@color/green_nature_header"
android:padding="3dp"
android:text="@string/label_keywords"
android:textColor="@color/White"
android:textStyle="bold" />
<TextView
android:id="@+id/tv_cbp_keywords"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="3dp"
android:text="@string/double_dash" />
<TextView
android:id="@+id/tv_cbp_modified"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="3dp"
android:text="@string/double_dash"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
</ScrollView>