首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Back-Button返回第一个对话框窗口

使用Back-Button返回第一个对话框窗口
EN

Stack Overflow用户
提问于 2012-01-30 02:43:33
回答 1查看 231关注 0票数 0

当一个新的或者更确切地说是下一个对话框正在运行时,我无法返回到第一个对话框窗口。

我的目标是通过单击back按钮打开之前的对话框。我如何才能做到这一点??

我尝试了几种方法,但都不能解决我的问题。下面是我的代码:

代码语言:javascript
复制
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();
EN

回答 1

Stack Overflow用户

发布于 2012-01-30 04:19:03

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9055688

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档