Example usage for android.app AlertDialog setButton

List of usage examples for android.app AlertDialog setButton

Introduction

In this page you can find the example usage for android.app AlertDialog setButton.

Prototype

public void setButton(int whichButton, CharSequence text, OnClickListener listener) 

Source Link

Document

Set a listener to be invoked when the positive button of the dialog is pressed.

Usage

From source file:cm.aptoide.pt.ApkInfo.java

public void loadMalware(final MalwareStatus malwareStatus) {
    runOnUiThread(new Runnable() {

        @Override//from w w w  .  ja  v  a2s.co m
        public void run() {
            try {
                EnumApkMalware apkStatus = EnumApkMalware
                        .valueOf(malwareStatus.getStatus().toUpperCase(Locale.ENGLISH));
                Log.d("ApkInfoMalware-malwareStatus", malwareStatus.getStatus());
                Log.d("ApkInfoMalware-malwareReason", malwareStatus.getReason());

                switch (apkStatus) {
                case SCANNED:
                    ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.trusted));
                    ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_scanned);
                    ((LinearLayout) findViewById(R.id.badge_layout)).setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            View trustedView = LayoutInflater.from(ApkInfo.this)
                                    .inflate(R.layout.dialog_anti_malware, null);
                            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ApkInfo.this)
                                    .setView(trustedView);
                            final AlertDialog trustedDialog = dialogBuilder.create();
                            trustedDialog.setIcon(R.drawable.badge_scanned);
                            trustedDialog.setTitle(getString(R.string.app_trusted, viewApk.getName()));
                            trustedDialog.setCancelable(true);

                            TextView tvSignatureValidation = (TextView) trustedView
                                    .findViewById(R.id.tv_signature_validation);
                            tvSignatureValidation.setText(getString(R.string.signature_verified));
                            ImageView check_signature = (ImageView) trustedView
                                    .findViewById(R.id.check_signature);
                            check_signature.setImageResource(R.drawable.ic_yes);

                            trustedDialog.setButton(Dialog.BUTTON_NEUTRAL, "Ok", new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface arg0, int arg1) {
                                    trustedDialog.dismiss();
                                }
                            });
                            trustedDialog.show();
                        }
                    });
                    break;
                //             case UNKNOWN:
                //                ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.unknown));
                //                ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_unknown);
                //                break;
                case WARN:
                    ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.warning));
                    ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_warn);
                    ((LinearLayout) findViewById(R.id.badge_layout)).setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            View warnView = LayoutInflater.from(ApkInfo.this)
                                    .inflate(R.layout.dialog_anti_malware, null);
                            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ApkInfo.this)
                                    .setView(warnView);
                            final AlertDialog warnDialog = dialogBuilder.create();
                            warnDialog.setIcon(R.drawable.badge_warn);
                            warnDialog.setTitle(getString(R.string.app_warning, viewApk.getName()));
                            warnDialog.setCancelable(true);

                            TextView tvSignatureValidation = (TextView) warnView
                                    .findViewById(R.id.tv_signature_validation);
                            tvSignatureValidation.setText(getString(R.string.signature_not_verified));
                            ImageView check_signature = (ImageView) warnView.findViewById(R.id.check_signature);
                            check_signature.setImageResource(R.drawable.ic_failed);

                            warnDialog.setButton(Dialog.BUTTON_NEUTRAL, "Ok", new Dialog.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface arg0, int arg1) {
                                    warnDialog.dismiss();
                                }
                            });
                            warnDialog.show();
                        }
                    });
                    break;
                //             case CRITICAL:
                //                ((TextView) findViewById(R.id.app_badge_text)).setText(getString(R.string.critical));
                //                ((ImageView) findViewById(R.id.app_badge)).setImageResource(R.drawable.badge_critical);
                //                break;
                default:
                    break;
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    });

}

From source file:com.android.mms.ui.MessageUtils.java

public static void addNumberOrEmailtoContact(final String numberOrEmail, final int REQUEST_CODE,
        final Activity activity) {
    if (!TextUtils.isEmpty(numberOrEmail)) {
        String message = activity.getResources().getString(R.string.add_contact_dialog_message, numberOrEmail);
        AlertDialog.Builder builder = new AlertDialog.Builder(activity).setTitle(numberOrEmail)
                .setMessage(message);// w  ww  .ja v a2 s.c om
        AlertDialog dialog = builder.create();
        dialog.setButton(AlertDialog.BUTTON_POSITIVE,
                activity.getResources().getString(R.string.add_contact_dialog_existing),
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
                        intent.setType(Contacts.CONTENT_ITEM_TYPE);
                        if (Mms.isEmailAddress(numberOrEmail)) {
                            intent.putExtra(ContactsContract.Intents.Insert.EMAIL, numberOrEmail);
                        } else {
                            intent.putExtra(ContactsContract.Intents.Insert.PHONE, numberOrEmail);
                        }
                        if (REQUEST_CODE > 0) {
                            activity.startActivityForResult(intent, REQUEST_CODE);
                        } else {
                            activity.startActivity(intent);
                        }
                    }
                });

        dialog.setButton(AlertDialog.BUTTON_NEGATIVE,
                activity.getResources().getString(R.string.add_contact_dialog_new),
                new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub
                        final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
                        if (Mms.isEmailAddress(numberOrEmail)) {
                            intent.putExtra(ContactsContract.Intents.Insert.EMAIL, numberOrEmail);
                        } else {
                            intent.putExtra(ContactsContract.Intents.Insert.PHONE, numberOrEmail);
                        }
                        if (REQUEST_CODE > 0) {
                            activity.startActivityForResult(intent, REQUEST_CODE);
                        } else {
                            activity.startActivity(intent);
                        }
                    }
                });
        dialog.show();
    }
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Creates a application informative dialog with options to
 * uninstall/launch or cancel.//w ww  .  j  a  v  a 2 s.co m
 * 
 * @param context
 * @param appPackage
 */
public static void appInfo_getLaunchUninstallDialog(final Context context, String appPackage) {

    try {

        final PackageManager packageManager = context.getPackageManager();
        final PackageInfo app = packageManager.getPackageInfo(appPackage, PackageManager.GET_META_DATA);

        AlertDialog dialog = new AlertDialog.Builder(context).create();

        dialog.setTitle(app.applicationInfo.loadLabel(packageManager));

        String description = null;
        if (app.applicationInfo.loadDescription(packageManager) != null) {
            description = app.applicationInfo.loadDescription(packageManager).toString();
        }

        String msg = app.applicationInfo.loadLabel(packageManager) + "\n\n" + "Version " + app.versionName
                + " (" + app.versionCode + ")" + "\n" + (description != null ? (description + "\n") : "")
                + app.applicationInfo.sourceDir + "\n" + appInfo_getSize(app.applicationInfo.sourceDir);
        dialog.setMessage(msg);

        dialog.setCancelable(true);
        dialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Cancel", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
        });
        dialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Uninstall", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                Intent intent = new Intent(Intent.ACTION_DELETE);
                intent.setData(Uri.parse("package:" + app.packageName));
                context.startActivity(intent);
            }
        });
        dialog.setButton(AlertDialog.BUTTON_POSITIVE, "Launch", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                Intent i = packageManager.getLaunchIntentForPackage(app.packageName);
                context.startActivity(i);
            }
        });

        dialog.show();
    } catch (Exception e) {
        if (LOG_ENABLE) {
            Log.e(TAG, "Dialog could not be made for the specified application '" + appPackage + "'. ["
                    + e.getMessage() + "].", e);
        }
    }
}

From source file:com.plusot.senselib.SenseMain.java

private void showTweetWarning() {
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle(R.string.warn_tweet_cloud_title);
    alertDialog.setMessage(getString(R.string.warn_tweet_cloud_msg));
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.button_confirm),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    return;
                }// w  ww. ja  v  a 2 s. c  o m
            });
    alertDialog.show();
}

From source file:com.plusot.senselib.SenseMain.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override//  w  w w . j  a  va 2s .  c om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    shouldFinish = 0;
    if (Build.VERSION.SDK_INT >= 11)
        requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY); //.FEATURE_ACTION_BAR_OVERLAY);
    Log.d(Globals.TAG,
            CLASSTAG + ".onCreate:\n" + "   ******************************************************\n"
                    + "   *                                                    *\n"
                    + "   *                                                    *\n"
                    + "   *                  SenseMain Started                 *\n"
                    + "   *                                                    *\n"
                    + "   *                                                    *\n"
                    + "   ******************************************************");

    if (Build.VERSION.SDK_INT < 14 || ViewConfiguration.get(this).hasPermanentMenuKey())
        requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.main);
    ActivityUtil.lockScreenOrientation(this);

    app = (SenseApp) getApplication();
    app.activityCreated(SenseMain.this);
    init(getIntent(), true);

    watchId = Watchdog.addProcessS(CLASSTAG);

    String state = android.os.Environment.getExternalStorageState();
    if (!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
        AlertDialog alertDialog = new AlertDialog.Builder(SenseMain.this).create();
        alertDialog.setTitle(R.string.no_sd_title);
        alertDialog.setMessage(SenseMain.this.getString(R.string.no_sd_message));
        alertDialog.setButton(DialogInterface.BUTTON_POSITIVE,
                SenseMain.this.getString(R.string.button_confirm), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        return;
                    }
                });
        alertDialog.show();
    }
    if (SenseGlobals.screenLock)
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); //ActivityUtil.lockScreenOrientation(SenseMain.this);
    updateSettings();
    PreferenceHelper.getPrefs().registerOnSharedPreferenceChangeListener(this);
    LLog.i(Globals.TAG, CLASSTAG + ".onCreate. Wakelock acquired");

    Device.setListener(SenseMain.this);
    HttpSender.checkSession();
    if (System.currentTimeMillis() - Value.getSessionTime() > 3600000L * 12
            && SenseGlobals.stopState.equals(SenseGlobals.StopState.PAUZE)) {
        closeValues(SenseGlobals.ActivityMode.STOP, false);
        PreferenceKey.setStopState(SenseGlobals.StopState.STOP);
    }
    if (SenseApp.firstActivity && SenseGlobals.loadSplash) {
        //creating = true;
        showSplashScreen(true);
        if (SenseGlobals.isBikeApp) {
            View view = this.findViewById(R.id.main_layout);
            if (view != null)
                view.setVisibility(View.INVISIBLE);
        }
    }
    SenseApp.firstActivity = false;
    Watchdog.getInstance().add(this, 1000);
    Watchdog.getInstance().add(this);

    //for (PreferenceKey prefKey : PreferenceKey.values()) updateSetting(prefs, prefKey);
    //if (PreferenceKey.HASMAP.isTrue()) addMap();
    try {
        PackageInfo info = getPackageManager().getPackageInfo(getPackageName(), 0);
        setTitle(Globals.appName + " " + info.versionName);
    } catch (NameNotFoundException ignored) {

    }
    File file = new File(SenseGlobals.getGpxPath());
    if (!file.isDirectory() && !file.mkdirs()) {
        Log.w(Globals.TAG, CLASSTAG + " Could not create: " + SenseGlobals.getGpxPath());
    }
}

From source file:group.pals.android.lib.ui.filechooser.FragmentFiles.java

/**
 * Confirms user to create new directory.
 *//*from w w  w  . j ava 2 s . co  m*/
private void showNewDirectoryCreationDialog() {
    final AlertDialog dialog = Dlg.newAlertDlg(getActivity());

    View view = getLayoutInflater(null).inflate(R.layout.afc_simple_text_input_view, null);
    final EditText textFile = (EditText) view.findViewById(R.id.afc_text1);
    textFile.setHint(R.string.afc_hint_folder_name);
    textFile.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                Ui.showSoftKeyboard(v, false);
                dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
                return true;
            }
            return false;
        }
    });

    dialog.setView(view);
    dialog.setTitle(R.string.afc_cmd_new_folder);
    dialog.setIcon(android.R.drawable.ic_menu_add);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    final String name = textFile.getText().toString().trim();
                    if (!FileUtils.isFilenameValid(name)) {
                        Dlg.toast(getActivity(), getString(R.string.afc_pmsg_filename_is_invalid, name),
                                Dlg.LENGTH_SHORT);
                        return;
                    }

                    new LoadingDialog<Void, Void, Uri>(getActivity(), false) {

                        @Override
                        protected Uri doInBackground(Void... params) {
                            return getActivity().getContentResolver().insert(
                                    BaseFile.genContentUriBase(getCurrentLocation().getAuthority()).buildUpon()
                                            .appendPath(getCurrentLocation().getLastPathSegment())
                                            .appendQueryParameter(BaseFile.PARAM_NAME, name)
                                            .appendQueryParameter(BaseFile.PARAM_FILE_TYPE,
                                                    Integer.toString(BaseFile.FILE_TYPE_DIRECTORY))
                                            .build(),
                                    null);
                        }// doInBackground()

                        @Override
                        protected void onPostExecute(Uri result) {
                            super.onPostExecute(result);

                            if (result != null) {
                                Dlg.toast(getActivity(), getString(R.string.afc_msg_done), Dlg.LENGTH_SHORT);
                            } else
                                Dlg.toast(getActivity(),
                                        getString(R.string.afc_pmsg_cannot_create_folder, name),
                                        Dlg.LENGTH_SHORT);
                        }// onPostExecute()

                    }.execute();
                }// onClick()
            });
    dialog.show();
    Ui.showSoftKeyboard(textFile, true);

    final Button buttonOk = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
    buttonOk.setEnabled(false);

    textFile.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            /*
             * Do nothing.
             */
        }// onTextChanged()

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            /*
             * Do nothing.
             */
        }// beforeTextChanged()

        @Override
        public void afterTextChanged(Editable s) {
            buttonOk.setEnabled(FileUtils.isFilenameValid(s.toString().trim()));
        }// afterTextChanged()
    });
}

From source file:info.zamojski.soft.towercollector.MainActivity.java

private void displayNewVersionDownloadOptions(Bundle extras) {
    UpdateInfo updateInfo = (UpdateInfo) extras.getSerializable(UpdateCheckAsyncTask.INTENT_KEY_UPDATE_INFO);
    // display dialog
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    LayoutInflater inflater = LayoutInflater.from(this);
    View dialogLayout = inflater.inflate(R.layout.new_version, null);
    dialogBuilder.setView(dialogLayout);
    final AlertDialog alertDialog = dialogBuilder.create();
    alertDialog.setCanceledOnTouchOutside(true);
    alertDialog.setCancelable(true);/*from w ww . ja v a  2  s  .  c  o  m*/
    alertDialog.setTitle(R.string.updater_dialog_new_version_available);
    // load data
    ArrayAdapter<UpdateInfo.DownloadLink> adapter = new UpdateDialogArrayAdapter(alertDialog.getContext(),
            inflater, updateInfo.getDownloadLinks());
    ListView listView = (ListView) dialogLayout.findViewById(R.id.download_options_list);
    listView.setAdapter(adapter);
    // bind events
    final CheckBox disableAutoUpdateCheckCheckbox = (CheckBox) dialogLayout
            .findViewById(R.id.download_options_disable_auto_update_check_checkbox);
    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            DownloadLink downloadLink = (DownloadLink) parent.getItemAtPosition(position);
            Log.d("displayNewVersionDownloadOptions(): Selected position: %s", downloadLink.getLabel());
            boolean disableAutoUpdateCheckCheckboxChecked = disableAutoUpdateCheckCheckbox.isChecked();
            Log.d("displayNewVersionDownloadOptions(): Disable update check checkbox checked = %s",
                    disableAutoUpdateCheckCheckboxChecked);
            if (disableAutoUpdateCheckCheckboxChecked) {
                MyApplication.getPreferencesProvider().setUpdateCheckEnabled(false);
            }
            MyApplication.getAnalytics().sendUpdateAction(downloadLink.getLabel());
            String link = downloadLink.getLink();
            try {
                startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
            } catch (ActivityNotFoundException ex) {
                Toast.makeText(getApplication(), R.string.web_browser_missing, Toast.LENGTH_LONG).show();
            }
            alertDialog.dismiss();
        }
    });
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(R.string.dialog_cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    boolean disableAutoUpdateCheckCheckboxChecked = disableAutoUpdateCheckCheckbox.isChecked();
                    Log.d("displayNewVersionDownloadOptions(): Disable update check checkbox checked = %s",
                            disableAutoUpdateCheckCheckboxChecked);
                    if (disableAutoUpdateCheckCheckboxChecked) {
                        MyApplication.getPreferencesProvider().setUpdateCheckEnabled(false);
                    }
                }
            });
    alertDialog.show();
}

From source file:cm.aptoide.pt.MainActivity.java

private void showAddStoreCredentialsDialog(String string) {
    View credentialsDialogView = LayoutInflater.from(mContext).inflate(R.layout.dialog_add_pvt_store, null);
    AlertDialog credentialsDialog = new AlertDialog.Builder(mContext).setView(credentialsDialogView).create();
    credentialsDialog.setTitle(getString(R.string.add_private_store) + " " + RepoUtils.split(string));
    credentialsDialog.setButton(Dialog.BUTTON_NEUTRAL, getString(R.string.new_store),
            new AddStoreCredentialsListener(string, credentialsDialogView));
    credentialsDialog.show();//from  ww  w  .jav  a  2 s.com
}

From source file:cm.aptoide.pt.MainActivity.java

private void showUpdateStoreCredentialsDialog(String string) {
    View credentialsDialogView = LayoutInflater.from(mContext).inflate(R.layout.dialog_add_pvt_store, null);
    AlertDialog credentialsDialog = new AlertDialog.Builder(mContext).setView(credentialsDialogView).create();
    credentialsDialog.setTitle(getString(R.string.add_private_store) + " " + RepoUtils.split(string));
    credentialsDialog.setButton(Dialog.BUTTON_NEUTRAL, getString(R.string.new_store),
            new UpdateStoreCredentialsListener(string, credentialsDialogView));
    credentialsDialog.show();/*w  w  w. ja  v a2  s.  c o m*/
}

From source file:com.haibison.android.anhuu.FragmentFiles.java

/**
 * Confirms user to create new directory.
 *///from   w w w  .ja  v  a2  s. c o  m
private void showNewDirectoryCreationDialog() {
    final AlertDialog dialog = Dlg.newAlertDlg(getActivity());

    View view = getLayoutInflater(null).inflate(R.layout.anhuu_f5be488d_simple_text_input_view, null);
    final EditText textFile = (EditText) view.findViewById(R.id.anhuu_f5be488d_text1);
    textFile.setHint(R.string.anhuu_f5be488d_hint_folder_name);
    textFile.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                UI.showSoftKeyboard(v, false);
                dialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
                return true;
            }
            return false;
        }
    });

    dialog.setView(view);
    dialog.setTitle(R.string.anhuu_f5be488d_cmd_new_folder);
    dialog.setIcon(android.R.drawable.ic_menu_add);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    final String name = textFile.getText().toString().trim();
                    if (!FileUtils.isFilenameValid(name)) {
                        Dlg.toast(getActivity(),
                                getString(R.string.anhuu_f5be488d_pmsg_filename_is_invalid, name),
                                Dlg.LENGTH_SHORT);
                        return;
                    }

                    new LoadingDialog<Void, Void, Uri>(getActivity(), false) {

                        @Override
                        protected Uri doInBackground(Void... params) {
                            return getActivity().getContentResolver().insert(
                                    BaseFile.genContentUriBase(getCurrentLocation().getAuthority()).buildUpon()
                                            .appendPath(getCurrentLocation().getLastPathSegment())
                                            .appendQueryParameter(BaseFile.PARAM_NAME, name)
                                            .appendQueryParameter(BaseFile.PARAM_FILE_TYPE,
                                                    Integer.toString(BaseFile.FILE_TYPE_DIRECTORY))
                                            .build(),
                                    null);
                        }// doInBackground()

                        @Override
                        protected void onPostExecute(Uri result) {
                            super.onPostExecute(result);

                            if (result != null) {
                                Dlg.toast(getActivity(), getString(R.string.anhuu_f5be488d_msg_done),
                                        Dlg.LENGTH_SHORT);
                            } else
                                Dlg.toast(getActivity(),
                                        getString(R.string.anhuu_f5be488d_pmsg_cannot_create_folder, name),
                                        Dlg.LENGTH_SHORT);
                        }// onPostExecute()

                    }.execute();
                }// onClick()
            });
    dialog.show();
    UI.showSoftKeyboard(textFile, true);

    final Button buttonOk = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
    buttonOk.setEnabled(false);

    textFile.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            /*
             * Do nothing.
             */
        }// onTextChanged()

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            /*
             * Do nothing.
             */
        }// beforeTextChanged()

        @Override
        public void afterTextChanged(Editable s) {
            buttonOk.setEnabled(FileUtils.isFilenameValid(s.toString().trim()));
        }// afterTextChanged()
    });
}