【问题标题】:Dynamically adding the text view in android在android中动态添加文本视图
【发布时间】:2011-10-13 18:37:39
【问题描述】:

我是安卓新手 我的表格布局包含一个表格行。这一行分别在第一列和第二列中有两个文本视图。

谁能告诉我如何在表格行中动态添加这两个文本视图??

【问题讨论】:

    标签: android textview tablelayout


    【解决方案1】:

    如果您已使用 TableRow 将内容视图设置为布局:

    TextView tv1 = new TextView(this);
    TextView tv2 = new TextView(this);
    TableRow tr = (TableRow)findViewById(R.id.<your table row id>);
    
    //apply layout params to your TextViews, set text etc...
    
    tr.addView(tv1);
    tr.addView(tv2);
    

    【讨论】:

    • 我正在将内容视图设置为相对布局..这个相对布局在其中包含表格布局..我收到 tr.addView(tv1) 的错误...对此有什么帮助吗?
    • 您遇到了哪个错误?在添加 textView 和 xml 布局的位置发布部分代码
    • 这是我的后端 TableRow tr =(TableRow)findViewById(R.id.trId); tournameText = (TextView) findViewById(R.id.tourname); tournameText.setText(tourResponse.getTourname()); dateText = (TextView) findViewById(R.id.dateText); dateText.setText(tourResponse.getFormattedDate()); tr.addView(tournameText); tr.addView(dateText);
    • 你的布局上有 dateText 和 tournameText(R.id.tourname) 吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-07
    • 1970-01-01
    相关资源
    最近更新 更多