如何在Android中将数据从ArrayList绑定到TableLayout? [英] How to bind data from ArrayList to TableLayout in Android?
本文介绍了如何在Android中将数据从ArrayList绑定到TableLayout?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 Android 中创建应用程序时遇到一个问题.在我的应用程序中,我将 ArrayList 数据绑定到 TableLayout.当我运行应用程序时,只绑定了最后一列数据.我要求绑定所有列.请帮帮我...
I have one problem to create my application in Android. Here in my application I bind the ArrayList Data into TableLayout. When I run the application, only the last column of data is bound. I have required all columns to be bound. Please help me...
我提供了我的代码:
查看Task.xml:
View Task.xml:
<TableLayout
android:id="@+id/score_table1"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow></TableRow>
</TableLayout>
查看task.java:
View task.java:
TableLayout table = (TableLayout) findViewById(R.id.score_table1);
for(int i=0;i<object.size();i++)
{
TableRow row=new TableRow(ViewTask.this);
@SuppressWarnings("unchecked")
ArrayList<String> data1 = (ArrayList<String>) object.get(i);
TextView taskdate = new TextView(ViewTask.this);
taskdate.setTextSize(10);
taskdate.setText(data1.get(0).toString());
row.addView(taskdate);
TextView title = new TextView(ViewTask.this);
taskdate.setText(data1.get(1).toString());
row.addView(title);
taskdate.setTextSize(10);
TextView taskhour = new TextView(ViewTask.this);
taskdate.setText(data1.get(2).toString());
taskhour.setTextSize(10);
row.addView(taskhour);
TextView description = new TextView(ViewTask.this);
taskdate.setText(data1.get(3).toString());
row.addView(description);
description.setTextSize(10);
table.addView(row);
}
推荐答案
您正在 for
循环中创建多个 textView
但仅将文本设置为第一个 textTiew
.
You're creating multiple textView
in the for
loop but setting text only to the first textTiew
.
TextView taskdate = new TextView(ViewTask.this);
taskdate.setTextSize(10);
taskdate.setText(data1.get(0).toString());
row.addView(taskdate);
TextView title = new TextView(ViewTask.this);
taskdate.setText(data1.get(1).toString());
row.addView(title);
taskdate.setTextSize(10);
TextView taskhour = new TextView(ViewTask.this);
taskdate.setText(data1.get(2).toString());
taskhour.setTextSize(10);
row.addView(taskhour);
TextView description = new TextView(ViewTask.this);
taskdate.setText(data1.get(3).toString());
row.addView(description);
description.setTextSize(10);
注意,使用 taskdate
变量,您正在多次设置文本.
Observe that with the taskdate
variable, you are setting text multiple times.
这篇关于如何在Android中将数据从ArrayList绑定到TableLayout?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文