创建表后,不会填充行。我所拥有的只是列标题“fName”。fName.setText 似乎不起作用。我检查以确保completedWord.get(0)
有一个值,并且确实如此。布局可能有问题,但我不确定。有什么建议么?
public void displayList () {
int rowCount = completedWords.size();
Log.d("Fill table", "rowCount = " + rowCount);
TableLayout table = (TableLayout) this.findViewById(R.id.tablelayout);
for (int i = 0; i <rowCount; i++) {
fillRow(table, i);
}
}
public void fillRow(TableLayout table, int noRow) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View fullRow = inflater.inflate(R.layout.activity_main, null, false);
TextView fName = (TextView) fullRow.findViewById(R.id.fName);
System.out.println("Table should read " + completedWords.get(noRow));
fName.setText(completedWords.get(noRow));
fName.setId(noRow + 1);
table.addView(fullRow);
}
XML 文件:
<RelativeLayout 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"
tools:context=".MainActivity"
android:gravity="center_horizontal"
android:background ="#268496" >
<EditText
android:focusable="true"
android:focusableInTouchMode="true"
android:id="@+id/input"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text"
android:layout_toRightOf="@+id/prefix"
android:textSize="12pt"
android:maxLength="1"
android:typeface="sans" />
<TextView
android:id="@id/prefix"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textIsSelectable="true"
android:textSize="12pt"
android:typeface="sans" />
<TableLayout
android:id="@+id/tablelayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:shrinkColumns="0"
android:gravity="center_horizontal"
android:layout_below="@id/prefix" >
<TextView
android:id="@+id/fName"
android:layout_marginTop="17dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"
android:textIsSelectable="true"
android:textSize="7pt"
android:typeface="sans"
android:text="Found words" />
</TableLayout>
</RelativeLayout>