2011-11-27 30 views
0

我有以下代碼:問題追加錶行表的佈局

HashMap<String, String> tip = venue.tips.get(j); 
      TableRow tr = new TableRow(this); 
      TableRow.LayoutParams tableRowParams = 
        new TableRow.LayoutParams 
        (TableRow.LayoutParams.FILL_PARENT,TableRow.LayoutParams.WRAP_CONTENT); 
      tr.setLayoutParams(tableRowParams); 

      LinearLayout ll = new LinearLayout(this); 
      ll.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); 

      TextView tips = new TextView(this); 
      tips.setText(tip.get("text")); 
      Log.v("TIPS TEXT", tip.get("text")); 
      tips.setLayoutParams(new LayoutParams(
        LayoutParams.WRAP_CONTENT, 
        LayoutParams.WRAP_CONTENT)); 

      ImageView avatar = new ImageView(this); 
      avatar.setImageBitmap(getBitmapFromURL(tip.get("photo"))); 
      Log.v("PHOTO URL", tip.get("photo")); 
      avatar.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 

      ll.addView(tips); 
      ll.addView(avatar); 

      tr.addView(ll); 

      View v = new View(this); 
      v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1)); 
      v.setBackgroundColor(Color.rgb(51, 51, 51)); 

      tipsTable.addView(tr,new TableLayout.LayoutParams(
         LayoutParams.FILL_PARENT, 
         LayoutParams.WRAP_CONTENT)); 
      tipsTable.addView(v); 

我覺得我做錯了什麼事與建立佈局,但現在的問題是,我不能看到行加入到tipsTable。爲什麼是這樣?

回答

0

你不打電話setContentView()任何地方。您創建此佈局但從不將其分配給活動。我想你想要做的是你已經設置了所有的佈局東西后:

setContentView(ll); 
+0

這樣做,讓我錯了 – xonegirlz

0

沿着相同的路線:tipsTable似乎是你俯視所以儘量的setContentView(tipsTable)