2012-01-11 15 views
0

私はAndroid 2.2でエミュレータ上で自分のコードを実行しています。しかし、デバイス(Galaxy S 2.3.3)に置くと、テーブルの要素のリストを表示するメイン画面が空白のままになります。ただし、トーストはapp_nameで表示されます。TableLayoutはエミュレータでうまく見えますが、デバイスではありません

この表は、ボタン(XMLで定義)とDBからロードされた要素のリストで構成されています。

ここにコード

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<TableLayout android:id="@+id/TableLayoutMain" 
    android:layout_width="match_parent" android:layout_height="wrap_content"> 
    <TableRow> 
     <Button android:text="@string/add_button" android:id="@+id/add_button" 
      android:layout_height="wrap_content" android:layout_marginTop="10dp" 
      android:layout_marginBottom="10dp" android:layout_width="match_parent" 
      android:layout_weight="1"></Button> 
    </TableRow> 
</TableLayout> 
</ScrollView> 

そしてmain.xml

:私はXMLの定義とプログラム的に追加要素間の混合がうまくいくかどうかわからなかった

public void showList(Cursor c){ 

    setContentView(R.layout.main);  
    table = (TableLayout) findViewById(R.id.TableLayoutMain); 

    do { 
     TableRow tr = new TableRow(this);   
     final int id = c.getInt(c.getColumnIndex(DatabaseAdapter.KEY_ROWID)); 
     tr.setId(id);   
     tr.setBackgroundColor(ROW_COLOR);   

     tr.setOnLongClickListener(new View.OnLongClickListener() { 

      @Override 
      public boolean onLongClick(View v) { 

       //do stuff 

       return true; 
      } 
     }); 

     tr.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       //do other stuff 
      } 
     });      

     TextView txt = getText(active, id, name); 
     tr.addView(txt); 
     table.addView(tr);   

    } while (c.moveToNext()); 
    c.close(); 
} 

。しかし、私は様々な組み合わせを試して、どちらも同じように悪いと言うことができます。つまり、エミュレータでは問題なく、デバイスでは問題ありません。 アンドロイド2.3.3で仮想デバイスを作成しましたが、コードは正常に動作します...それで、Androidバージョンではないと思います。何かご意見は?

+0

"ROW_COLOR"の宣言はどこですか? – lv0gun9

+0

申し訳ありませんが、言及を忘れています:それはクラスで宣言された定数です。 – hansdampf

答えて

0

完了したら、相対レイアウトをTableLayoutの親として使用して作業します。正確には私が望んだものではありませんが、それは動作します...

関連する問題