Exemple #1
0
  public boolean onOptionsItemSelected(MenuItem item) {
    context = this;

    switch (item.getItemId()) {
      case MENU_IMPORT:
        // Get the content of the directory
        profileFiles = getProfileList();
        if (profileFiles != null && profileFiles.length > 0) {
          // Show dialog with the files
          new AlertDialog.Builder(this)
              .setTitle(getString(R.string.settings_profile_dialog_profiles_title))
              .setIcon(android.R.drawable.ic_menu_upload)
              .setItems(profileFiles, profileOnClick)
              .show();
        } else {
          Toast.makeText(this, "No profile found.", Toast.LENGTH_SHORT).show();
        }
        return true;

      case MENU_EXPORT:
        exportSettings();
        break;

      case MENU_DELETE:
        // Get the content of the directory
        profileFiles = getProfileList();
        new AlertDialog.Builder(this)
            .setTitle(getString(R.string.settings_profile_dialog_delete_title))
            .setIcon(android.R.drawable.ic_menu_delete)
            .setItems(
                profileFiles,
                new DialogInterface.OnClickListener() {
                  // Ask the user to be sure to delete it
                  public void onClick(DialogInterface dialog, int whichItem) {
                    profileToDelete = whichItem;
                    new AlertDialog.Builder(context)
                        .setIcon(android.R.drawable.ic_dialog_alert)
                        .setTitle(getString(R.string.settings_profile_dialog_delete_title))
                        .setMessage(
                            getString(
                                R.string.settings_profile_dialog_delete_text,
                                profileFiles[whichItem]))
                        .setPositiveButton(android.R.string.ok, deleteOkButtonClick)
                        .setNegativeButton(android.R.string.cancel, null)
                        .show();
                  }
                })
            .show();
        return true;
    }

    return false;
  }