Java Code Examples for android.app.AlertDialog.Builder#setItems()

The following examples show how to use android.app.AlertDialog.Builder#setItems() . 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: Main.java    From screenstandby with GNU General Public License v2.0 8 votes vote down vote up
private void openVideoClip()
  {
  	Builder watchDialog = new AlertDialog.Builder(this).setCancelable(true);
watchDialog.setTitle("Select a video clip:");
watchDialog.setIcon(android.R.drawable.ic_menu_slideshow);
watchDialog.setItems(clipsName, new android.content.DialogInterface.OnClickListener() {
	@Override
	public void onClick(DialogInterface dialog, int which) {
		if (which >= 0) {
			Intent youtubeIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=" + clipsUrl[which]));
           	youtubeIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
           	startActivity(youtubeIntent);							
		}
	}});
watchDialog.setNegativeButton("Dismiss", null);
watchDialog.show();
  }
 
Example 2
Source File: LogsFragment.java    From callmeter with GNU General Public License v3.0 8 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean onItemLongClick(final AdapterView<?> parent, final View view,
        final int position, final long id) {
    final Builder b = new Builder(getActivity());
    b.setCancelable(true);
    b.setItems(R.array.dialog_delete, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            LogsFragment.this
                    .getActivity()
                    .getContentResolver()
                    .delete(ContentUris.withAppendedId(DataProvider.Logs.CONTENT_URI, id),
                            null, null);
            LogsFragment.this.setAdapter(true);
            LogRunnerService.update(LogsFragment.this.getActivity(), null);
        }
    });
    b.setNegativeButton(android.R.string.cancel, null);
    b.show();
    return true;
}
 
Example 3
Source File: SingleChoiceDialogFragment.java    From barterli_android with Apache License 2.0 5 votes vote down vote up
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {

    if (savedInstanceState != null) {
        mTitleId = savedInstanceState.getInt(DialogKeys.TITLE_ID);
        isCancellable = savedInstanceState
                        .getBoolean(DialogKeys.CANCELLABLE);
        mIconId = savedInstanceState.getInt(DialogKeys.ICON_ID);
        mTheme = savedInstanceState.getInt(DialogKeys.THEME);
        mItemsId = savedInstanceState.getInt(DialogKeys.ITEMS_ID);
    }

    final Builder builder = new Builder(getActivity(), mTheme);

    if (mItemsId == 0) {
        throw new IllegalArgumentException("No items available to add");
    }

    builder.setItems(mItemsId, mClickListener);

    if (mIconId != 0) {
        builder.setIcon(mIconId);
    }
    if (mTitleId != 0) {
        builder.setTitle(mTitleId);
    }

    builder.setCancelable(isCancellable);
    setCancelable(isCancellable);
    return builder.create();
}
 
Example 4
Source File: HourGroupEdit.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceClick(final Preference preference) {
    String k = preference.getKey();
    if (k != null && k.startsWith("item_")) {
        final long id = Long.parseLong(k.substring("item_".length()));

        final Builder builder = new Builder(this);
        builder.setItems(R.array.dialog_edit_delete,
                new android.content.DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        switch (which) {
                            case WHICH_EDIT:
                                HourGroupEdit.this.showHourDialog(id);
                                break;
                            case WHICH_DELETE:
                                HourGroupEdit.this.getContentResolver().delete(
                                        ContentUris
                                                .withAppendedId(DataProvider.Hours.CONTENT_URI,
                                                        id), null, null);
                                HourGroupEdit.this.reload();
                                RuleMatcher.unmatch(HourGroupEdit.this);
                                break;
                            default:
                                break;
                        }
                    }
                });
        builder.setNegativeButton(android.R.string.cancel, null);
        builder.show();
    }
    return false;
}
 
Example 5
Source File: NumberGroupEdit.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onPreferenceClick(final Preference preference) {
    String k = preference.getKey();
    if (k != null && k.startsWith("item_")) {
        final long id = Long.parseLong(k.substring("item_".length()));

        final Builder builder = new Builder(this);
        builder.setItems(R.array.dialog_edit_delete,
                new android.content.DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int which) {
                        switch (which) {
                            case WHICH_EDIT:
                                NumberGroupEdit.this.showNumberDialog(id);
                                break;
                            case WHICH_DELETE:
                                NumberGroupEdit.this.getContentResolver().delete(
                                        ContentUris.withAppendedId(
                                                DataProvider.Numbers.CONTENT_URI, id), null,
                                        null);
                                NumberGroupEdit.this.reload();
                                RuleMatcher.unmatch(NumberGroupEdit.this);
                                break;
                            default:
                                break;
                        }
                    }
                });
        builder.setNegativeButton(android.R.string.cancel, null);
        builder.show();
    }

    return false;
}
 
Example 6
Source File: PlansFragment.java    From callmeter with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean onItemLongClick(final AdapterView<?> parent, final View view,
        final int position, final long id) {
    final Builder builder = new Builder(getActivity());
    builder.setItems(R.array.dialog_edit_plan,
            new android.content.DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, final int which) {
                    switch (which) {
                        case 0:
                            Intent intent = new Intent(PlansFragment.this.getActivity(),
                                    PlanEdit.class);
                            intent.setData(ContentUris.withAppendedId(
                                    DataProvider.Plans.CONTENT_URI, id));
                            PlansFragment.this.getActivity().startActivity(intent);
                            break;
                        case 1:
                            ((Plans) PlansFragment.this.getActivity()).showLogsFragment(id);
                            break;
                        default:
                            break;
                    }
                }
            });
    builder.setNegativeButton(android.R.string.cancel, null);
    builder.show();
    return true;
}