如何从ArrayList中的数据绑定到TableLayout在Android的? [英] how to bind data from ArrayList to TableLayout in Android?

查看:431
本文介绍了如何从ArrayList中的数据绑定到TableLayout在Android的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,创造我的Andr​​oid应用程序。
在这里,在我的应用程序将绑定ArrayList的数据到TableLayout。
当我将运行应用程序当时只是最后一列的数据绑定。我有需要的绑定所有列。请帮我...

我有我提供code:

查看Task.xml,

 < TableLayout
                机器人:ID =@ + ID / score_table1
                机器人:layout_width =FILL_PARENT
                机器人:layout_height =WRAP_CONTENT>
                <&的TableRow GT;< /&的TableRow GT;
 < / TableLayout>

查看task.java,

  TableLayout表=(TableLayout)findViewById(R.id.score_table1);            的for(int i = 0; I< object.size();我++)
            {
                    连续的TableRow =新的TableRow(ViewTask.this);                    @燮pressWarnings(未登记)
                    ArrayList的<串GT; DATA1 =(ArrayList的&所述;字符串&GT)object.get(ⅰ);                    TextView的taskdate =新的TextView(ViewTask.this);
                    taskdate.setTextSize(10);
                    taskdate.setText(data1.get(0)的ToString());
                    row.addView(taskdate);                    TextView的标题=新的TextView(ViewTask.this);
                    taskdate.setText(data1.get(1)的ToString());
                    row.addView(职称);
                    taskdate.setTextSize(10);
                    TextView的taskhour =新的TextView(ViewTask.this);
                    taskdate.setText(data1.get(2)的ToString());
                    taskhour.setTextSize(10);
                    row.addView(taskhour);
                    TextView中描述=新的TextView(ViewTask.this);
                    taskdate.setText(data1.get(3)的ToString());
                    row.addView(介绍);
                    description.setTextSize(10);                    table.addView(行);            }


解决方案

您创建多个的TextView 在循环,但将文本第一 textTiew

  TextView的taskdate =新的TextView(ViewTask.this);
                taskdate.setTextSize(10);
                taskdate.setText(data1.get(0)的ToString());
                row.addView(taskdate);                TextView的标题=新的TextView(ViewTask.this);
                taskdate.setText(data1.get(1)的ToString());
                row.addView(职称);
                taskdate.setTextSize(10);
                TextView的taskhour =新的TextView(ViewTask.this);
                taskdate.setText(data1.get(2)的ToString());
                taskhour.setTextSize(10);
                row.addView(taskhour);
                TextView中描述=新的TextView(ViewTask.this);
                taskdate.setText(data1.get(3)的ToString());
                row.addView(介绍);
                description.setTextSize(10);

观察taskdate变量要为它多次设置文本

i have one problem to create my application in Android. Here In my Application I will Bind the ArrayList Data into TableLayout. when i will run the application that time only last column data are bind. i have require all column are bind. Please help me...

I have provide my code:

View Task.xml,

<TableLayout
                android:id="@+id/score_table1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">
                <TableRow></TableRow>
 </TableLayout>

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);

            }               

解决方案

Your creating multiple textView in for loop but setting text to first textTiew only

 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);

observe taskdate variable you are setting text for it multiple times

这篇关于如何从ArrayList中的数据绑定到TableLayout在Android的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆