当一个新的或者更确切地说是下一个对话框正在运行时,我无法返回到第一个对话框窗口。
我的目标是通过单击back按钮打开之前的对话框。我如何才能做到这一点??
我尝试了几种方法,但都不能解决我的问题。下面是我的代码:
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();发布于 2012-01-30 04:19:03
为第一个对话框使用一个单独的类,并将android:theme="@android:style/Theme.Dialog"添加到AndroidManifest中该类的<activity>标记中。如果不调用finish(),它就会被添加到后台堆栈中。
https://stackoverflow.com/questions/9055688
复制相似问题