2012-04-14 57 views
1

3列のTableLayoutを作成しようとしていますが、何も表示されません。私は何を取得、私はエラーメッセージを取得していない動的に作成されたアンドロイドでコンテンツが表示されないTableLayout

<?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="wrap_content" 
android:orientation="vertical" 
android:id="@+id/LinearLayout1" > 



<TableLayout 
    android:id="@+id/tableLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="350dp" 
    android:layout_marginTop="10dp" 
    > 

</TableLayout> 


<Button 
    android:id="@+id/BorrarPedido" 
    android:layout_width="204dp" 
    android:layout_height="wrap_content" 
    android:text="Borrar Pedido" 
    android:layout_gravity="center" /> 

<Button 
    android:id="@+id/EnviarPedido" 
    android:layout_width="204dp" 
    android:layout_height="wrap_content" 
    android:text="Enviar Pedido" 
    android:layout_gravity="center" /> 

    </LinearLayout> 

:ここ

  TableLayout tl = (TableLayout)findViewById(R.id.tableLayout1); 
     TableRow tr = new TableRow(this); 
     tr.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT)); 


     TextView tv = new TextView(this); 
     tv.setLayoutParams(new LayoutParams(
        LayoutParams.FILL_PARENT, 
        LayoutParams.WRAP_CONTENT)); 
     tv.setText(data[0]); 
     tr.addView(tv); 

     TextView tv1 = new TextView(this); 
     tv1.setLayoutParams(new LayoutParams(
       LayoutParams.FILL_PARENT, 
       LayoutParams.WRAP_CONTENT)); 
     tv1.setText(data[1]); 
     tr.addView(tv1); 

     TextView tv2 = new TextView(this); 
     tv2.setLayoutParams(new LayoutParams(
       LayoutParams.FILL_PARENT, 
       LayoutParams.WRAP_CONTENT)); 
     tv2.setText(data[2]); 
     tr.addView(tv2); 

     /* Add row to TableLayout. */ 
     tl.addView(tr,new TableLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); 

そして、私のXMLファイルは、次のとおりです。ここに私のJavaコードです。問題は、TableLayoutの外にある2 Buttonsを除いて、私は何も見ることができません。なぜこのようなことが起こるのか?

+0

がvalues.AlsoがTextViews .SometimesのSETTEXTCOLORあなたの活動のテーマを設定してみてください持つデータが混乱 –

+0

を引き起こす可能性があり、データがVAを持ってい確かに、ルーズ。私はtextviewの色を変更しようとしましたが、まだビューには何もありません。 – Aldridge1991

答えて

0

は次のように試してみてください:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" > 

    <TableLayout 
     android:id="@+id/tableLayout1" 
     android:layout_width="fill_parent" 
     android:layout_height="350dp" 
     android:layout_marginTop="10dp" android:stretchColumns="*" > 
    </TableLayout> 

    <Button 
     android:id="@+id/BorrarPedido" 
     android:layout_width="204dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="Borrar Pedido" /> 

    <Button 
     android:id="@+id/EnviarPedido" 
     android:layout_width="204dp" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="Enviar Pedido" /> 
</LinearLayout> 


    TableLayout tblLayout = (TableLayout)findViewById(R.id.tableLayout1); 

    TableLayout.LayoutParams layoutParams = new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT, TableLayout.LayoutParams.WRAP_CONTENT); 

    TableRow row = new TableRow(this); 
    row.setBackgroundColor(Color.DKGRAY); 
    tblLayout.addView(row, layoutParams); 

    addToTableRow("Name", row, Color.WHITE); 
    addToTableRow("Age", row, Color.WHITE); 
    addToTableRow("Location", row, Color.WHITE); 
    } 

    private void addToTableRow(String str, TableRow row,int color) 
    { 
    TextView t = new TextView(this); 
    t.setTextColor(color); 
    t.setText(str); 
    row.addView(t); 
    } 
+0

アンドロイド:オリエンテーションはとても重要ですか? – deadfish

3

あなたTextView sがTableRowの子供はあなたがLayoutParamsの代わりに、(ViewGroupスーパークラスから多分)簡単なもののためにTableRow.LayoutParamsのインスタンスを設定する必要があることあなたの現在使用:

//... 
     TextView tv = new TextView(this); 
     tv.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 
       TableRow.LayoutParams.WRAP_CONTENT)); 
     tv.setText("text 1"); 
     tr.addView(tv); 

     TextView tv1 = new TextView(this); 
     tv1.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 
       TableRow.LayoutParams.WRAP_CONTENT)); 
     tv1.setText("text 2"); 
     tr.addView(tv1); 

     TextView tv2 = new TextView(this); 
     tv2.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 
       TableRow.LayoutParams.WRAP_CONTENT)); 
     tv2.setText("text 3"); 
     tr.addView(tv2); 
//... 
+0

私にも同様の問題が解決しました...ありがと... – anni

関連する問題