android.content.DialogInterface.OnMultiChoiceClickListener Java Examples

The following examples show how to use android.content.DialogInterface.OnMultiChoiceClickListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AlertDialogUtils.java    From FlyWoo with Apache License 2.0 6 votes vote down vote up
/**
 * @param context
 * @param s
 * @param okcallback
 */
public static void showSelectFriends(Context context, final String[] s, final MultCallBack okcallback) {
    new Builder(context).setMultiChoiceItems(s, new boolean[]{},
            new OnMultiChoiceClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                    List<Integer> checked = new ArrayList<Integer>();
                    for (int i = 0; i < s.length; i++) {
                        if (i == which && isChecked) {
                            // ��ʾѡ����
                            checked.add(i);
                        }
                    }
                    okcallback.onOkClick(checked);
                    dialog.dismiss();
                }
            }).show();
}
 
Example #2
Source File: PreferenceFragment.java    From AndroidMaterialDialog with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a listener, which allows to show a toast, which indicates when a multi
 * choice list item of a dialog has been selected or unselected.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * OnClickListener}
 */
private OnMultiChoiceClickListener createMultiChoiceListener() {
    return new OnMultiChoiceClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int position,
                            final boolean isChecked) {
            String text = getString(R.string.multi_choice_listener_selected_text);

            if (!isChecked) {
                text = getString(R.string.multi_choice_listener_unselected_text);
            }

            if (toast != null) {
                toast.cancel();
            }

            showToast(String.format(text, position));
        }

    };
}
 
Example #3
Source File: MultiChoiceListPreference.java    From AndroidMaterialPreferences with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a listener, which allows to observe when list items are selected or
 * unselected by the user.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * OnMultiChoiceClickListener}
 */
private OnMultiChoiceClickListener createListItemListener() {
    return new OnMultiChoiceClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int which,
                            final boolean isChecked) {
            if (isChecked) {
                selectedIndices.add(which);
            } else {
                selectedIndices.remove(which);
            }
        }

    };
}
 
Example #4
Source File: AlertDialogUtils.java    From Conquer with Apache License 2.0 6 votes vote down vote up
/**
 * 多选对话框
 * 
 * @param context
 * @param s
 * @param okcallback
 */
public static void showSelectFriends(Context context, final String[] s, final MultCallBack okcallback) {
    new Builder(context).setMultiChoiceItems(s, new boolean[] {},
            new OnMultiChoiceClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                    List<Integer> checked = new ArrayList<Integer>();
                    for (int i = 0; i < s.length; i++) {
                        if (i == which && isChecked) {
                            // 表示选中了
                            checked.add(i);
                        }
                    }
                    okcallback.onOkClick(checked);
                    dialog.dismiss();
                }
            }).show();
}
 
Example #5
Source File: MainActivity.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
public void dialog2(View view) {
	// 1.Builder
	AlertDialog.Builder builder = new AlertDialog.Builder(this);
	// 2.���ñ��⡢���ݡ�����
	builder.setTitle("����ϲ����֧���");
	/*
	 * ����1������Դ����
	 * 
	 * ����2:ÿ��ѡ���Ĭ�ϳ�ʼ�ĵ��״̬boolean����
	 * 
	 */
	builder.setMultiChoiceItems(items, isChecks,
			new OnMultiChoiceClickListener() {

				// ����������ǰ���DZ�ѡ�л���ȡ��
				@Override
				public void onClick(DialogInterface dialog, int which,
						boolean isChecked) {
					// ����һ������ַ���
					StringBuilder sb = new StringBuilder();
					// ѭ������ѡ�����ݣ���ȡѡ��������ݣ���ƴ�ӵ������
					for (int i = 0; i < items.length; i++) {
						// �����ǰ����ѡ�У�ƴ�ӵ������
						if (isChecks[i]) {
							sb.append(items[i]).append("\n");
						}
					}
					Toast.makeText(MainActivity.this, sb.toString(),
							Toast.LENGTH_SHORT).show();
				}
			});
	// 3.��ʾ
	builder.show();
}
 
Example #6
Source File: MaterialAlertDialogBuilder.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public MaterialAlertDialogBuilder setMultiChoiceItems(
    @ArrayRes int itemsId,
    @Nullable boolean[] checkedItems,
    @Nullable final OnMultiChoiceClickListener listener) {
  return (MaterialAlertDialogBuilder) super.setMultiChoiceItems(itemsId, checkedItems, listener);
}
 
Example #7
Source File: MaterialAlertDialogBuilder.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public MaterialAlertDialogBuilder setMultiChoiceItems(
    @Nullable CharSequence[] items,
    @Nullable boolean[] checkedItems,
    @Nullable final OnMultiChoiceClickListener listener) {
  return (MaterialAlertDialogBuilder) super.setMultiChoiceItems(items, checkedItems, listener);
}
 
Example #8
Source File: MaterialAlertDialogBuilder.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public MaterialAlertDialogBuilder setMultiChoiceItems(
    @Nullable Cursor cursor,
    @NonNull String isCheckedColumn,
    @NonNull String labelColumn,
    @Nullable final OnMultiChoiceClickListener listener) {
  return (MaterialAlertDialogBuilder)
      super.setMultiChoiceItems(cursor, isCheckedColumn, labelColumn, listener);
}
 
Example #9
Source File: MultiSelectListPreference.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected void onPrepareDialogBuilder(Builder builder) {
	builder.setMultiChoiceItems(getEntries(), checkedEntryIndexes,
			new OnMultiChoiceClickListener() {

				@Override
				public void onClick(DialogInterface dialog, int which,
						boolean isChecked) {
					checkedEntryIndexes[which] = isChecked;
				}
			});
}
 
Example #10
Source File: PreferenceDialogBuilder.java    From MaterialPreference with Apache License 2.0 4 votes vote down vote up
public PreferenceDialogBuilder setMultiChoiceItems(int itemsId, boolean[] checkedItems, OnMultiChoiceClickListener listener) {
    mBuilder.setMultiChoiceItems(itemsId, checkedItems, listener);
    return this;
}
 
Example #11
Source File: PreferenceDialogBuilder.java    From MaterialPreference with Apache License 2.0 4 votes vote down vote up
public PreferenceDialogBuilder setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems, OnMultiChoiceClickListener listener) {
    mBuilder.setMultiChoiceItems(items, checkedItems, listener);
    return this;
}
 
Example #12
Source File: PreferenceDialogBuilder.java    From MaterialPreference with Apache License 2.0 4 votes vote down vote up
public PreferenceDialogBuilder setMultiChoiceItems(Cursor cursor, String isCheckedColumn, String labelColumn, OnMultiChoiceClickListener listener) {
    mBuilder.setMultiChoiceItems(cursor, isCheckedColumn, labelColumn, listener);
    return this;
}
 
Example #13
Source File: PreferenceDialogBuilder.java    From MaterialPreference with Apache License 2.0 4 votes vote down vote up
public PreferenceDialogBuilder setMultiChoiceItems(int itemsId, boolean[] checkedItems, OnMultiChoiceClickListener listener) {
    mBuilder.setMultiChoiceItems(itemsId, checkedItems, listener);
    return this;
}
 
Example #14
Source File: PreferenceDialogBuilder.java    From MaterialPreference with Apache License 2.0 4 votes vote down vote up
public PreferenceDialogBuilder setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems, OnMultiChoiceClickListener listener) {
    mBuilder.setMultiChoiceItems(items, checkedItems, listener);
    return this;
}
 
Example #15
Source File: PreferenceDialogBuilder.java    From MaterialPreference with Apache License 2.0 4 votes vote down vote up
public PreferenceDialogBuilder setMultiChoiceItems(Cursor cursor, String isCheckedColumn, String labelColumn, OnMultiChoiceClickListener listener) {
    mBuilder.setMultiChoiceItems(cursor, isCheckedColumn, labelColumn, listener);
    return this;
}
 
Example #16
Source File: OnMultiChoiceClickListenerWrapper.java    From AndroidMaterialDialog with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new wrapper, which implements the interface {@link OnItemClickListener} in order to
 * delegate the method calls to encapsulated listener of the type {@link
 * OnMultiChoiceClickListener}.
 *
 * @param listener
 *         The listener, which should be encapsulated by the wrapper, as an instance of the type
 *         {@link OnMultiChoiceClickListener} or null, if no listener should be encapsulated
 * @param dialog
 *         The dialog, the listener should belong to, as an instance of the type {@link
 *         ValidateableDialog}. The dialog may not be null
 * @param buttonType
 *         The type of the button or list item, the listener belongs to, as an {@link Integer}
 *         value
 */

public OnMultiChoiceClickListenerWrapper(@Nullable final OnMultiChoiceClickListener listener,
                                         @NonNull final ValidateableDialog dialog,
                                         final int buttonType) {
    super(dialog, buttonType);
    this.wrappedListener = listener;
}