【问题标题】:Return to first Dialog Window with Back-Button使用返回按钮返回第一个对话框窗口
【发布时间】:2012-01-29 18:43:33
【问题描述】:

当新的或下一个对话框正在运行时,我无法返回到第一个对话框窗口。

我的目标是通过单击后退按钮打开对话框。我怎样才能做到这一点??

我尝试了几件事,但无法解决我的问题。这是我的代码:

AlertDialog.Builder builder = new AlertDialog.Builder(context);
                builder.setTitle("AP's");
                builder.setItems(scannedAP, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            Cursor cursor = dbAdapter.queryRssiBlob(scannedMacSsid[which][mac],scannedMacSsid[which][ssid],coord[GridConfig.curXCoord],coord[GridConfig.curYCoord]);
                            if (cursor != null && cursor.moveToFirst()) {
                                byte[] rssiArrayOne = cursor.getBlob(cursor.getColumnIndex("rssi"));
                                cursor.close();
                                ObjectInputStream objectIn = new ObjectInputStream(new ByteArrayInputStream(rssiArrayOne));
                                List<Integer> readRssi = (List<Integer>) objectIn.readObject();
                                rssiList = new CharSequence[readRssi.size()];
                                for (int index = 0; index < readRssi.size(); index++) {
                                    rssiList[index] = "" + readRssi.get(index);
                                }
                                AlertDialog.Builder build = new AlertDialog.Builder(context);
                                build.setTitle("RSSi values");
                                build.setItems(rssiList, new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {}
                                    });
                                build.setOnKeyListener(new DialogInterface.OnKeyListener() {
                                    public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event2) {
                                        if (keyCode == KeyEvent.KEYCODE_BACK) {
                                            return false;
                                        }
                                        return true;
                                    }   
                                    });
                                AlertDialog alertBuild = build.create();
                                alertBuild.show();
                            } else {
                                Toast.makeText(context, "No Values", Toast.LENGTH_SHORT).show();
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }

                    }

                });
                AlertDialog alert = builder.create();
                alert.show();

【问题讨论】:

    标签: android android-activity dialog android-alertdialog


    【解决方案1】:

    为第一个对话框使用单独的类,并将android:theme="@android:style/Theme.Dialog" 添加到AndroidManifest 中该类的&lt;activity&gt; 标记。如果您不调用finish(),它将被添加到后台堆栈中。

    【讨论】:

    • 感谢您的帮助,我会尽快尝试
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多