2
在我的應用我試圖打開一個對話框時活動開始,它有一個積極的按鈕。點擊該按鈕後,新的活動將打開。它的工作很好,下面的代碼。但是當我長按菜單按鈕或搜索按鈕對話框就會消失。即使我按菜單或搜索按鈕,如何使該對話框保持不變。謝謝。爲什麼對話框disapear當搜索按鈕按下
public class Sam3Activity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView title = new TextView(this);
title.setText("DM2");
title.setBackgroundColor(Color.DKGRAY);
title.setPadding(10, 10, 10, 10);
title.setGravity(Gravity.CENTER);
title.setTextColor(Color.WHITE);
title.setTextSize(20);
/* alert message */
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setCustomTitle(title);
builder.setMessage("dialog with message").setCancelable(false).setPositiveButton(
"Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.dismiss();
Log.d("choose","on dissmiss");
startActivity(new Intent(getApplicationContext(),
StatisticDisplay.class));//second activity
}
});
AlertDialog alert = builder.create();
alert.show();
}
}
對不起,我是在檢查響應有點晚了。 – thej
thej沒問題 –