-2
我想創建在自定義對話框內動態創建的表格佈局。誰能告訴我如何做到這一點?如何使用動態表格佈局來拋棄自定義對話框?
我做了一些事情,但沒有在對話框中顯示。該對話框中沒有表格佈局。
有誰能告訴我我犯了什麼錯誤嗎? 這是我的活動:
LayoutInflater inflater = getActivity().getLayoutInflater();
View dialog_view = inflater.inflate(R.layout.progressdialog, null);
AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
dialog.setView(dialog_view);
TableLayout table_layout = (TableLayout)dialog_view.findViewById(R.id.Table_view_in_dialog);
for (int i = 1; i <= 4; i++) {
TableRow row = new TableRow(getActivity());
row.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
// inner for loop
for (int j = 1; j <= 4; j++) {
TextView tv = new TextView(getActivity());
tv.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
tv.setBackgroundResource(R.drawable.cell_shape);
tv.setPadding(5, 5, 5, 5);
tv.setText("R " + i + ", C" + j);
row.addView(tv);
}
table_layout.addView(row);
}
AlertDialog alert = dialog.create();
alert.show();