我正在創建一個android應用程序,它提供了自定義對話框。在我已經放置的自定義對話框中放置了一個動態生成的表格佈局。通過執行該對話框顯示一個帶有對話框標題標題的空白對話框,它不會在該對話框中顯示任何表格佈局,任何人都可以幫助我如何查看動態定製對話框內表佈局 這是我的活動如何在自定義對話框中放置表格佈局?
alert_progress_dialog = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = (LayoutInflater)getActivity().getSystemService(getActivity().LAYOUT_INFLATER_SERVICE);
alert_progress_dialog.setTitle("MANUAL MODE : TESTING ");
View dialogview = inflater.inflate(R.layout.progressdialog, null);
alert_progress_dialog.setView(dialogview);
alert_progress_dialog.setMessage("This is a sample message");
table_dialog = (TableLayout)dialogview.findViewById(R.id.table_layout_1);
for (int i = 1; i <= 4; i++) {
TableRow row = new TableRow(getActivity());
row.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
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_dialog.addView(row);
}
alert_progress_dialog.show();
這是我的xml文件的對話框內撥打:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableLayout
android:id="@+id/table_layout_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="77dp" >
</TableLayout>
</RelativeLayout>
因此,每次有問題時,您都會創建2或3個重複項,從未回答試圖幫助您的人,並基本上污染了重複項的重複項。 – 2Dee
可能重複[如何在線程內部動態創建表格佈局](http://stackoverflow.com/questions/31140323/how-to-create-table-layout-dynamically-inside-thread) – 2Dee