2015-06-30 60 views
2

我正在創建一個由應用程序自定義報警對話框組成的Android應用程序。在該對話框中,我想動態創建一個包含4行和5列的表格佈局。我想在螺紋處,以使這個任何一個可以告訴我如何創建動態表格佈局內螺紋這是我做了什麼,但它是隻顯示對話框的名字,但沒有內螺紋 表格的佈局編輯:如何在線程內動態創建表格佈局

progresDialog = new Dialog(getActivity()); 
       progresDialog.setContentView(R.layout.progressdialog); 
       progresDialog.setTitle("MANUAL MODE : TESTING "); 
       testing_after_fuse_cnc = new Thread(new Runnable() { 

        @Override 
        public void run() { 
        update_handler.post(new Runnable() { 

         @Override 
         public void run() { 
          table_dialog = new TableLayout(getActivity()); 
          table_dialog.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT)); 
          table_dialog.setBackgroundColor(Color.parseColor("#FFFFFF")); 
          for(i=1;i<3;i++){ 
           tablerow_dialog = new TableRow(getActivity()); 
           tablerow_dialog.setLayoutParams(new LayoutParams(android.widget.TableRow.LayoutParams.WRAP_CONTENT,android.widget.TableRow.LayoutParams.WRAP_CONTENT)); 
           for(j=1;j<4;j++){ 
            TextView t_v_dialog = new TextView(getActivity()); 
            t_v_dialog.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
            t_v_dialog.setBackgroundResource(R.drawable.cell_shape); 
            t_v_dialog.setPadding(5,5,5, 5); 
            tablerow_dialog.addView(t_v_dialog); 

           } 

           table_dialog.addView(tablerow_dialog); 
          } 
         } 
        }); 

        } 
       }); 
       testing_after_fuse_cnc.start(); 
       progresDialog.show(); 
+0

此table_row從哪裏來? – Amsheer

回答

1

線條

table_row.addView(t_v_dialog); 
} 
table_dialog.addView(table_row); 

應該

tablerow_dialog.addView(t_v_dialog); 
} 
table_dialog.addView(tablerow_dialog); 

不要忘記添加table_dialog到您的佈局容器。

相關問題