【问题标题】:How to update tablerow textview?如何更新表格文本视图?
【发布时间】:2013-11-05 12:11:33
【问题描述】:

我有这个动态表格布局:

 <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="horizontal" >

                    <TableLayout
                        android:id="@+id/main_table"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_margin="2dip"
                        android:layout_weight="1"
                        android:stretchColumns="1" >
                    </TableLayout>
                </LinearLayout>

和代码:

tl = (TableLayout) findViewById(R.id.main_table);
...
// Create 5 columns to add as table data
            TextView labelid = new TextView(this);
            labelid.setId(count);
            labelid.setTextSize(20);
            labelid.setPadding(10, 10, 10, 10);
            labelid.setGravity(Gravity.CENTER);
            labelid.setText(readxml.getID() + " ");
            labelid.setTextColor(Color.BLACK);
            tr.addView(labelid);

            // Create 5 columns to add as table data
            TextView labelname = new TextView(this);
            labelname.setId(count);
            labelname.setTextSize(20);
            labelname.setPadding(10, 10, 10, 10);
            labelname.setGravity(Gravity.CENTER);
            labelname.setText(readxml.getName() + " ");
            labelname.setTextColor(Color.BLACK);
            tr.addView(labelname);

那么,如何更新 1 行 textviews 文本?

【问题讨论】:

    标签: android dynamic row android-tablelayout


    【解决方案1】:

    如果适合您的问题,我建议您使用 GridView,否则您可以查看this answer,这正是您所需要的。

    【讨论】:

    • 你的意思是把整个tablelayout改成griview?
    • 如果您有动态行并且它们很多,那么我认为这将是更有效的方法。
    【解决方案2】:

    将标签设置为 TextView 以回调它们

    例如

    //label tag
    labelid.setTag("labelid"+count);
    //text tag
    labelname.setTag("labelname"+count);
    

    并按位置调用 labelid 或 labelname

    //for example get first element added values
    
        int myid = 0;
        TextView labelid_text = (TextView) tl.findViewWithTag("labelid"+myid);
        TextView labelname_text = (TextView) tl.findViewWithTag("labelname"+myid);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多