2012-01-29 160 views
0

當新的對話框或下一個對話框運行時,我無法返回到第一個對話窗口。返回到帶有後退按鈕的第一個對話框窗口

我的目標是通過單擊後退按鈕打開對話框。我怎樣才能做到這一點?

我嘗試了幾件事,但無法解決我的問題。這裏是我的代碼:

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

回答

0

使用一個單獨的類的第一個對話框,並添加android:theme="@android:style/Theme.Dialog"<activity>標籤在AndroidManifest該類。如果你不叫finish()它會被添加到後臺。

+0

感謝您的幫助,我會盡快嘗試 – LikeMusic 2012-01-31 22:58:21

相關問題