动态添加的行未在android中显示

爷爷

请帮忙。当我调试应用程序时,添加了行,但表未显示在屏幕上,我已为此创建了单独的xmltablerowtablelayout位于主xml文件中

    table = (TableLayout) findViewById(R.id.goodsTable);

     for (int i = 0; i < attrName.length; i++) {
                            TableRow row = (TableRow) LayoutInflater.from(getApplicationContext()).inflate(R.layout.attribute_row, null);
                            ((TextView) row.findViewById(R.id.attributeName)).setText(attrName[i]);
                            ((TextView) row.findViewById(R.id.attributeValue)).setText(barcode);
                            table.addView(row);
                        }

attribute_row xml:

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:id="@+id/attributeName"
        android:layout_height="wrap_content"
        android:gravity="left"
        android:textStyle="bold"
        />

    <TextView
        android:id="@+id/attributeValue"
        android:layout_height="wrap_content"
        android:gravity="right" />
</TableRow>

主要xml文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="top"
        android:orientation="horizontal"
        android:padding="10dp">
        <EditText
            android:id="@+id/goodsBarcode"
            android:layout_width="262dp"
            android:layout_height="wrap_content"
            android:inputType="textCapWords"
            android:padding="10dp"
            android:singleLine="false"
            android:background="@android:color/transparent" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="search"
            android:id="@+id/search"
             />
        </LinearLayout>
    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <LinearLayout
            android:id="@+id/details"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            >
            <TableLayout
                android:id="@+id/goodsTable"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

            </TableLayout>
        </LinearLayout>
    </ScrollView>


</LinearLayout>

请帮忙; 当我调试应用程序时,会添加行,但表不会显示在屏幕上我已经为tablerow单独创建了xml,而tablelayout在主xml文件中

爷爷

经过两天的代码苦苦挣扎,终于解决了问题,我的错误是使用“ ApplicationContext”而不是“ Activity Context”;我需要使用TableRow row =(TableRow)Inflater.from(this).inflate(R.layout.attribute_row,table,false); 而不是TableRow row =(TableRow)LayoutInflater.from(getApplicationContext())。inflate(R.layout.attribute_row,table,false);

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

动态添加的行未在android中显示

来自分类Dev

动态添加的TextInputLayout未在LinearLayout中显示

来自分类Dev

将动态行添加到ngTable中不显示

来自分类Dev

将动态行添加到ngTable中不显示

来自分类Dev

添加远程选项未在PyCharm中显示

来自分类Dev

菜单中的图标未在android中显示

来自分类Dev

输出未在PHP中显示新行

来自分类Dev

未在Android应用中添加KML图层

来自分类Dev

SoftKeyboard未在Xamarin Android中显示

来自分类Dev

列未在Android的GridLayout中显示

来自分类Dev

卢比符号未在Android中显示

来自分类Dev

Android设备未在Eclipse中显示

来自分类Dev

数据未在gridView Android中显示

来自分类Dev

外部图片未在Android中显示

来自分类Dev

吐司未在Android Studio中显示

来自分类Dev

列未在Android的GridLayout中显示

来自分类Dev

数据未在gridView Android中显示

来自分类Dev

RestTemplate Spring未在Android中显示

来自分类Dev

GridView RowCommand事件未在动态添加的用户控件中触发

来自分类Dev

Jenkins动态管道未在BlueOcean中显示所有阶段

来自分类Dev

动态加载的Aspx内容未在DNN模块中显示

来自分类Dev

浏览器未在JSP中显示动态生成的CSS

来自分类Dev

在Android中动态添加EditText

来自分类Dev

在javascript中动态添加图片显示错误

来自分类Dev

在javascript中动态添加图片显示错误

来自分类Dev

添加未在模板中显示的关键字

来自分类Dev

动态将表数据和表行添加到HTML,TD不在HTML中显示

来自分类Dev

无法获取Android表布局中动态添加的行的行ID

来自分类Dev

添加动态行表不显示正确的行