如何在自定义对话框中放置表格布局? [英] How to place a table layout inside the custom dialog?

查看:140
本文介绍了如何在自定义对话框中放置表格布局?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个带有自定义对话框的android应用程序.在我放置的自定义对话框中,放置了一个动态生成的表格布局.执行该对话框时会显示一个带有对话框标题标题的空对话框,只是它没有在该对话框中显示任何表格布局,任何人都可以帮助我如何查看动态自定义对话框中的表格布局 这是我的活动

I am creating an android application which presents with custom dialog. In that custom dialog i had placed had placed a table layout generated dynamically.By executing that the dialog was showing an empty dialog with the dialog header title only it was not displaying any table layout inside that dialog can any one help me how to view dynamic table layout inside custom dialog This is my activity

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文件:

This is my xml file to call inside the dialog:

<?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>

推荐答案

使用Dialog而不是AlertDialog,然后将setContentView与您的布局ID一起使用.

Use Dialog instead of AlertDialog, then use setContentView with your layout id.

这篇关于如何在自定义对话框中放置表格布局?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆