0

ここに画像の説明を入力

テーブルを作成しても、行は移入されません。私が持っているのは、列のタイトル「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>
4

2 に答える 2

0

TextView を取得してテーブルに追加するためにR.layout.activity_mainをインフレートしないでください。TextViewを動的に作成してテーブルに追加できます。

public void fillRow(TableLayout table, int noRow) {
TableRow fullRow = new TableRow(this);
TextView fName = new TextView(this);
System.out.println("Table should read " + completedWords.get(noRow));
fName.setText(completedWords.get(noRow));//or u can try completedWords.elementAt(noRow)
fName.setId(noRow + 1);
table.addView(fullRow);
}
于 2013-05-10T15:47:31.407 に答える