Возврат в первое диалоговое окно с кнопкой Back - PullRequest
0 голосов
/ 29 января 2012

Я не могу вернуться к первому диалоговому окну, когда запускается новое или, вернее, следующее диалоговое окно.

Моя цель - открыть диалоговое окно, нажав кнопку «Назад».Как мне этого добиться ??

Я пробовал несколько вещей, но не смог решить свою проблему.Вот мой код:

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();

1 Ответ

0 голосов
/ 30 января 2012

используйте отдельный класс для первого диалога и добавьте android:theme="@android:style/Theme.Dialog" к тегу <activity> для этого класса в AndroidManifest.Если вы не позвоните finish(), он будет добавлен в backstack.

...