0

データベースからのコメントをテーブル行に表示したいのですが、データベースからコメント付きのデータを取得することは問題ありませんが、ページのタイトルを実行したアクティビティに何も表示されず、エラーが見つかりません: S

これがJavaの部分です:

public class PIComments extends Activity{

      public static final String EXTRA_IDPI="EXTRA_IDPI";
      TableLayout messagesTable;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.picomments);
            messagesTable = (TableLayout)findViewById(R.id.commentTable);

            long PIID = getIntent().getLongExtra(EXTRA_IDPI, 0);

            if(PIID>0){

                ArrayList<CommentMsg> comments = CommentMsg.getPIComments(PIID);

                if(comments != null){

                    for(int i=0; i<comments.size(); i++) {

                        // Create a TableRow and give it an ID
                        TableRow tr = new TableRow(this);
                        tr.setId(i);
                        tr.setLayoutParams(new LayoutParams(
                                LayoutParams.FILL_PARENT,
                                LayoutParams.WRAP_CONTENT));   

                        // Create a TextView to house the name of the province
                        TextView login = new TextView(this);
                        login.setId(i);
                        login.setText(comments.get(i).getMsg());
                        //login.setText(comments.get(i).getAuteur());
                        login.setTextColor(Color.BLACK);
                        login.setLayoutParams(new LayoutParams(
                                LayoutParams.FILL_PARENT,
                                LayoutParams.WRAP_CONTENT));
                        tr.addView(login);

                        // Add the TableRow to the TableLayout
                        messagesTable.addView(tr, new TableLayout.LayoutParams(
                                LayoutParams.FILL_PARENT,
                                LayoutParams.WRAP_CONTENT));

                    }
                }
                else{
                    Dialog d = new Dialog(PIComments.this);
                    d.setTitle("No comments for the moment ... ");
                    d.show();
                }
            }

        }

}

そしてxmlがあります:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffccd0"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp"
        android:background="#ffb0b6"
        android:text="Comments"
        android:textColor="#b3000d"
        android:textSize="26dp"
        android:textStyle="bold" />

    <LinearLayout
        android:id="@+id/ll_country"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <ScrollView
            android:id="@+id/ScrollView11"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:fillViewport="true" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp" >

                <TableLayout
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    android:id="@+id/commentTable"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:stretchColumns="0" >
                </TableLayout>

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

</LinearLayout>
4

1 に答える 1

1

了解しました。tl.addView(...)に提供されたものを除いて、すべてのLayoutParamsはandroid.widget.TableRow.LayoutParamsである必要があります。

/* Find Tablelayout defined in main.xml */
TableLayout tl = (TableLayout) findViewById(R.id.SaleOrderLines);
/* Create a new row to be added. */
TableRow tr = new TableRow(this);
tr.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
/* Create a Button to be the row-content. */
Button b = new Button(this);
b.setText("Dynamic Button");
b.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, TableRow.LayoutParams.WRAP_CONTENT));
/* Add Button to row. */
tr.addView(b);
/* Add row to TableLayout. */
//tr.setBackgroundResource(R.drawable.sf_gradient_03);
tl.addView(tr, new TableLayout.LayoutParams(TableLayout.LayoutParams.FILL_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));

また

私は同じ問題を抱えています、そして私は削除します

textView.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));

各テキストビューから、何かが表示されます。

また

textViewの色をに設定します

textView.setTextColor(Color.WHITE);

背景がテキストの色と一緒に黒である可能性があります:)

それでも、この非常に優れたチュートリアルを参照してください。何かが足りない可能性があります。Androidの動的TableLayout

これがお役に立てば幸いです。

ありがとう :)

于 2012-07-22T14:58:15.410 に答える