我在Android應用程序中有一個對話框,我不希望用戶能夠取消。使用.setCancelable(false)
將禁用後退按鈕,但按下搜索按鈕仍會取消對話框。我看到this question它告訴我,我應該包括在Android中禁用搜索按鈕
public boolean onSearchRequested() {
return false;
}
但我還是能夠取消與搜索按鈕關閉對話框。這裏是我的代碼:
public class TestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
showDialog(0);
}
public boolean onSearchRequested() {
return false;
}
protected Dialog onCreateDialog(int id) {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Message")
.setCancelable(false)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// nothing
}
});
return builder.create();
}
}
似乎這個問題已經回答:http://stackoverflow.com/questions/2502443/prevent-progressdialog-from-being-dismissed - 當我點擊搜索按鈕,然後 – mah 2012-03-23 00:09:49