Java Code Examples for android.content.DialogInterface.OnMultiChoiceClickListener

The following examples show how to use android.content.DialogInterface.OnMultiChoiceClickListener. These examples are extracted from open source projects. 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 Project: FlyWoo   Source File: AlertDialogUtils.java    License: 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 Project: AndroidMaterialDialog   Source File: PreferenceFragment.java    License: 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
/**
 * 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 Project: Conquer   Source File: AlertDialogUtils.java    License: 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 Project: Study_Android_Demo   Source File: MainActivity.java    License: 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
@NonNull
@Override
public MaterialAlertDialogBuilder setMultiChoiceItems(
    @ArrayRes int itemsId,
    @Nullable boolean[] checkedItems,
    @Nullable final OnMultiChoiceClickListener listener) {
  return (MaterialAlertDialogBuilder) super.setMultiChoiceItems(itemsId, checkedItems, listener);
}
 
Example 7
@NonNull
@Override
public MaterialAlertDialogBuilder setMultiChoiceItems(
    @Nullable CharSequence[] items,
    @Nullable boolean[] checkedItems,
    @Nullable final OnMultiChoiceClickListener listener) {
  return (MaterialAlertDialogBuilder) super.setMultiChoiceItems(items, checkedItems, listener);
}
 
Example 8
@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
@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
public PreferenceDialogBuilder setMultiChoiceItems(int itemsId, boolean[] checkedItems, OnMultiChoiceClickListener listener) {
    mBuilder.setMultiChoiceItems(itemsId, checkedItems, listener);
    return this;
}
 
Example 11
public PreferenceDialogBuilder setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems, OnMultiChoiceClickListener listener) {
    mBuilder.setMultiChoiceItems(items, checkedItems, listener);
    return this;
}
 
Example 12
public PreferenceDialogBuilder setMultiChoiceItems(Cursor cursor, String isCheckedColumn, String labelColumn, OnMultiChoiceClickListener listener) {
    mBuilder.setMultiChoiceItems(cursor, isCheckedColumn, labelColumn, listener);
    return this;
}
 
Example 13
public PreferenceDialogBuilder setMultiChoiceItems(int itemsId, boolean[] checkedItems, OnMultiChoiceClickListener listener) {
    mBuilder.setMultiChoiceItems(itemsId, checkedItems, listener);
    return this;
}
 
Example 14
public PreferenceDialogBuilder setMultiChoiceItems(CharSequence[] items, boolean[] checkedItems, OnMultiChoiceClickListener listener) {
    mBuilder.setMultiChoiceItems(items, checkedItems, listener);
    return this;
}
 
Example 15
public PreferenceDialogBuilder setMultiChoiceItems(Cursor cursor, String isCheckedColumn, String labelColumn, OnMultiChoiceClickListener listener) {
    mBuilder.setMultiChoiceItems(cursor, isCheckedColumn, labelColumn, listener);
    return this;
}
 
Example 16
/**
 * 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;
}