コード例 #1
0
  @Override
  protected void showDialog(Bundle state) {
    mEntries = getEntries();
    mEntryValues = getEntryValues();
    mValues = getValues();

    if (mEntries == null || mEntryValues == null) {
      throw new IllegalStateException(
          "ActionMultiSelectListPreference requires an entries array and "
              + "an entryValues array.");
    }

    boolean[] checkedItems = getSelectedItems();
    String[] str = new String[mEntries.length];
    int length = mEntries.length;
    for (int i = 0; i < length; i++) {
      str[i] = mEntries[i].toString();
    }

    mActionSheet = new ActionSheet(mContext);
    mActionSheet.setMultiChoiceItems(
        str,
        checkedItems,
        new MultiChoiceListener() {

          @Override
          public void onDismiss(ActionSheet actionSheet) {
            mActionSheet = null;
          }

          @Override
          public void onItemToggle(int which) {}

          @Override
          public void onConfirm(boolean[] itemStatus) {
            for (int i = 0; i < itemStatus.length; i++) {
              if (itemStatus[i]) {
                mPreferenceChanged |= mNewValues.add(mEntryValues[i].toString());
              } else {
                mPreferenceChanged |= mNewValues.remove(mEntryValues[i].toString());
              }
            }
            onDialogClosed(true);
          }
        },
        new ActionButton(
            mContext.getString(android.R.string.ok),
            mContext.getResources().getColor(R.color.hw_actionsheet_text_color),
            new OnClickListener() {
              @Override
              public void onClick(View v) {}
            }));

    mNewValues.clear();
    mNewValues.addAll(mValues);
    mActionSheet.showWithDialog();
  }
コード例 #2
0
  public void onActivityDestroy() {
    if (mActionSheet == null) {
      return;
    }

    mActionSheet.dismiss();
    super.onActivityDestroy();
  }