我正在创建和Android应用程序,其中包含动态创建的表格布局,我想在自定义对话框中显示该表格布局。我已调用生成的表格布局,该布局存在于对话框活动内的另一个活动中但是它显示空对话框的对话框名称可以任何人告诉我我在哪里做错了 这是我的动态表格布局生成活动:
EDIT:------------
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
menu.setHeaderTitle("MANUAL MODE : AFTER FUSE CONNECTION");
menu.add(1, v.getId(), 0, "TEST ");
menu.add(1, v.getId(), 0, "SELECT ALL ");
menu.add(1, v.getId(), 0, "DESELECT ALL ");
super.onCreateContextMenu(menu, v, menuInfo);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
if(item.getTitle()=="TEST ")
{
progresDialog = new Dialog(getActivity());
LayoutInflater inflater = (LayoutInflater)getActivity().getSystemService(getActivity().LAYOUT_INFLATER_SERVICE);
progresDialog.setTitle("MANUAL MODE : TESTING ");
View dialogview = inflater.inflate(R.layout.progressdialog, null);
progresDialog.setContentView(dialogview);
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);
}
progresDialog.show();
}
答案 0 :(得分:0)
这是因为你在对话框中调用了布局,但是你是通过java代码创建布局的。你需要在下面给出的东西:
1.如果您创建DialogFragment,请将其更改为AlertDialog或更合适。 2.而不是使用
dialog.setContentView(layout id);
使用它:
dialog.setContentView(view object);
如何使用这种方法?让我给你看一个示例
LayoutInflater = (LayoutInflater) getSystemService(Context.LAYOU_INFLATER_SERVICE);
View dialogView = inflater.inflate(R.layout.activity_progressdialogactivity, null);
现在可以在此处识别您的表格布局:
table_layout = (TableLayout) dialogView.findViewById(R.id.tl_1);
然后在这里添加你的for循环;