请帮忙。当我调试应用程序时,添加了行,但表未显示在屏幕上,我已为此创建了单独的xmltablerow
并tablelayout
位于主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] 删除。
我来说两句