我正在创建一个包含自定义警报对话框的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();
解决方法:
线
table_row.addView(t_v_dialog);
}
table_dialog.addView(table_row);
应该
tablerow_dialog.addView(t_v_dialog);
}
table_dialog.addView(tablerow_dialog);
不要忘记将table_dialog添加到您的布局容器.