Activity 中的 showDialog 不显示对话框

发布于 2024-10-10 02:21:02 字数 2612 浏览 6 评论 0原文

这是我的代码:

public class TasksList extends ListActivity {
    ...
    private static final int COLUMNS_DIALOG = 7;
    private static final int ORDER_DIALOG = 8;
    private Bundle bundle = new Bundle();
    ...
     /**
     * @see android.app.Activity#onCreateDialog(int)
     */
    @Override
    protected Dialog onCreateDialog(int id) {
        Dialog dialog;
        final String[] columns;
        Cursor c = managedQuery(Tasks.CONTENT_URI, null, null, null, null);
        columns = c.getColumnNames();
        final String[] order = { "Ascending", "Descending" };

        switch (id) {
        case COLUMNS_DIALOG:
            AlertDialog.Builder columnDialog = new AlertDialog.Builder(this);
            columnDialog.setSingleChoiceItems(columns, -1, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    bundle.putString("column", columns[which]);
                }
            });
            dialog = columnDialog.create();
            break;
        case ORDER_DIALOG:
            AlertDialog.Builder orderDialog = new AlertDialog.Builder(this);
            orderDialog.setSingleChoiceItems(order, -1, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String orderS;
                    if (order[which].equalsIgnoreCase("Ascending"))
                        orderS = "ASC";
                     else
                        orderS = "DESC";

                    bundle.putString("order", orderS);
                }
            });
             dialog = orderDialog.create();
             break;
        default:
            dialog = null;
            break;
        }

        return dialog;
    }
    /**
     * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case SORT_MENU:
            showDialog(COLUMNS_DIALOG);
            showDialog(ORDER_DIALOG);
            String orderBy = bundle.getString("column") + bundle.getString("order");

            Cursor tasks = managedQuery(Tasks.CONTENT_URI, projection, null, null, orderBy);
            adapter = new TasksAdapter(this, tasks);
            getListView().setAdapter(adapter);

            break;
        case FILTER_MENU:
            break;
        }
        return false;
    }
}

showDialog 不显示对话框。我使用了调试器,它确实执行了这些语句,但对话框不显示。

Here is my code:

public class TasksList extends ListActivity {
    ...
    private static final int COLUMNS_DIALOG = 7;
    private static final int ORDER_DIALOG = 8;
    private Bundle bundle = new Bundle();
    ...
     /**
     * @see android.app.Activity#onCreateDialog(int)
     */
    @Override
    protected Dialog onCreateDialog(int id) {
        Dialog dialog;
        final String[] columns;
        Cursor c = managedQuery(Tasks.CONTENT_URI, null, null, null, null);
        columns = c.getColumnNames();
        final String[] order = { "Ascending", "Descending" };

        switch (id) {
        case COLUMNS_DIALOG:
            AlertDialog.Builder columnDialog = new AlertDialog.Builder(this);
            columnDialog.setSingleChoiceItems(columns, -1, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    bundle.putString("column", columns[which]);
                }
            });
            dialog = columnDialog.create();
            break;
        case ORDER_DIALOG:
            AlertDialog.Builder orderDialog = new AlertDialog.Builder(this);
            orderDialog.setSingleChoiceItems(order, -1, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String orderS;
                    if (order[which].equalsIgnoreCase("Ascending"))
                        orderS = "ASC";
                     else
                        orderS = "DESC";

                    bundle.putString("order", orderS);
                }
            });
             dialog = orderDialog.create();
             break;
        default:
            dialog = null;
            break;
        }

        return dialog;
    }
    /**
     * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case SORT_MENU:
            showDialog(COLUMNS_DIALOG);
            showDialog(ORDER_DIALOG);
            String orderBy = bundle.getString("column") + bundle.getString("order");

            Cursor tasks = managedQuery(Tasks.CONTENT_URI, projection, null, null, orderBy);
            adapter = new TasksAdapter(this, tasks);
            getListView().setAdapter(adapter);

            break;
        case FILTER_MENU:
            break;
        }
        return false;
    }
}

The showDialog doesn't display the dialog. I used the Debugger and it does executes these statements, but the dialog doesn't show.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月下客 2024-10-17 02:21:02

您不会破坏 onCreateDialog 中的 switch 语句。你每次都把它设置为空吗?

You're not breakaing from your switch statements in onCreateDialog. Are you just setting it null every time?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文