我想我的代碼來檢查我的對話框中寫入的內容是否包含某個字符串,如果不是無法關閉對話框。現在,當我按下按鈕,沒關係的對話框消失,儘管出現了敬酒的事實,所以我想我已經做了一些錯誤的setCancelable
如果字符串不包含某些單詞將無法離開對話框
protected void showInputDialog() {
// get prompts.xml view
LayoutInflater layoutInflater = LayoutInflater.from(MainActivity.this);
View promptView = layoutInflater.inflate(R.layout.url, null);
final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(MainActivity.this, AlertDialog.THEME_HOLO_DARK);
alertDialogBuilder.setView(promptView);
final EditText editText = (EditText) promptView.findViewById(R.id.Button01);
alertDialogBuilder.setTitle("Enter URL");
// alertDialogBuilder.setCustomTitle("Enter URL");
// alertDialogBuilder.setIcon(R.drawable.icon);
alertDialogBuilder.setCancelable(false);
alertDialogBuilder.setPositiveButton("DONE", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
String value = editText.getText().toString();
if (value.contains("www.facebook.com/")) {
//Toast.makeText(getBaseContext(), "You didn't enter the Name",Toast.LENGTH_SHORT).show();
// alertDialogBuilder.setCancelable(false);
}
else {
Toast.makeText(getBaseContext(), "You didn't enter the Name",Toast.LENGTH_SHORT).show();
alertDialogBuilder.setCancelable(false);
}
}
});
// create an alert dialog
AlertDialog alert = alertDialogBuilder.create();
alert.show();
}
任何建議如何解決呢?
編輯: 我已經發布了全功能的,雖然我不認爲它會幫助你
您發佈不夠代碼,上傳包含該代碼段的整體功能? –
@Derek Fung我發佈了整個代碼,請看看 –