Example usage for android.app AlertDialog.Builder setView

List of usage examples for android.app AlertDialog.Builder setView

Introduction

In this page you can find the example usage for android.app AlertDialog.Builder setView.

Prototype

public void setView(View view) 

Source Link

Document

Set the view to display in that dialog.

Usage

From source file:ch.pec0ra.mobilityratecalculator.ItineraryConfirmationDialog.java

@NonNull
@Override/*from w  w  w. j ava 2 s . co m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();
    final View v = inflater.inflate(R.layout.itinerary_confirmation_dialog, null);

    final String twoWay;
    if (itinerary.isTwoWay) {
        twoWay = getString(R.string.two_way);
    } else {
        twoWay = getString(R.string.one_way);
    }

    int distance = (int) Math.ceil((double) itinerary.distance / 1000);
    if (itinerary.isTwoWay) {
        distance = distance * 2;
    }
    final ImageView image = (ImageView) v.findViewById(R.id.map_image);
    image.setImageBitmap(itinerary.image);
    ((TextView) v.findViewById(R.id.from_text_view)).setText(getString(R.string.from_format, itinerary.from));
    ((TextView) v.findViewById(R.id.to_text_view)).setText(getString(R.string.to_format, itinerary.to));
    ((TextView) v.findViewById(R.id.two_way_text_view)).setText(twoWay);
    ((TextView) v.findViewById(R.id.total_distance_text_view))
            .setText(getString(R.string.distance_format, distance));

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    final int finalDistance = distance;
    builder.setView(v).setTitle(getString(R.string.itinerary))
            // Add action buttons
            .setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(final DialogInterface dialog, int id) {
                    mListener.onDialogPositiveClick(finalDistance);
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    ItineraryConfirmationDialog.this.getDialog().cancel();
                }
            });
    Dialog dialog = builder.create();
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    return builder.create();
}

From source file:com.eugene.fithealthmaingit.UI.NavFragments.FragmentJournalMainHome.java

/**
 * Display Calorie Goal Indicator Information
 *///from   w  w  w.  j a va 2  s.  c  o m
private void calorieInfoDialog(String s) {
    double calMin = mCalorieGoalMeal - 100;
    double calMax = mCalorieGoalMeal + 100;
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(s + " Calorie Goal")
            .setMessage("Goal:   " + df.format(calMin) + "  -  " + df.format(calMax) + " Calories")
            .setPositiveButton("Done", null);
    LayoutInflater inflater = getActivity().getLayoutInflater();
    FrameLayout f1 = new FrameLayout(getActivity());
    f1.addView(inflater.inflate(R.layout.dialog_calorie_info, f1, false));
    builder.setView(f1);
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.code.android.vibevault.SearchScreen.java

/** Handle user's long-click selection.
*
*///from  w w w . j a v a2  s .  c  o m
@Override
public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo menuInfo = (AdapterContextMenuInfo) item.getMenuInfo();
    if (menuInfo != null) {
        ArchiveShowObj selShow = (ArchiveShowObj) searchList.getAdapter().getItem(menuInfo.position);
        switch (item.getItemId()) {
        case VibeVault.EMAIL_LINK:
            final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
            emailIntent.setType("plain/text");
            emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                    "Great show on archive.org: " + selShow.getArtistAndTitle());
            emailIntent.putExtra(android.content.Intent.EXTRA_TEXT,
                    "Hey,\n\nYou should listen to " + selShow.getArtistAndTitle() + ".  You can find it here: "
                            + selShow.getShowURL() + "\n\nSent using VibeVault for Android.");
            startActivity(Intent.createChooser(emailIntent, "Send mail..."));
            return true;
        case VibeVault.SHOW_INFO:
            AlertDialog.Builder ad = new AlertDialog.Builder(this);
            ad.setTitle("Show Info");
            View v = LayoutInflater.from(this).inflate(R.layout.scrollable_dialog, null);
            ((TextView) v.findViewById(R.id.DialogText)).setText(selShow.getSource());
            ad.setPositiveButton("Okay.", new android.content.DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int arg1) {
                }
            });
            ad.setView(v);
            ad.show();
            return true;
        case (VibeVault.ADD_TO_FAVORITE_LIST):
            VibeVault.db.insertFavoriteShow(selShow);
            return true;
        default:
            return false;
        }
    }
    return false;
}

From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java

private void showFilterEditDialog() {

    @SuppressLint("InflateParams")
    LinearLayout dialogView = (LinearLayout) getLayoutInflater().inflate(R.layout.dialog_filter, null); // passing null okay for dialog

    ThemeManager.Theme theme = global.mThemeManager.getActiveTheme("appthemepref");
    int headerColor = Color.parseColor(theme.getValue("header_color"));
    int headerText = Color.parseColor(theme.getValue("header_text"));
    dialogView.findViewById(R.id.filter_header).setBackgroundColor(headerColor);
    ((TextView) dialogView.findViewById(R.id.filter_headert1)).setTextColor(headerText);
    ((TextView) dialogView.findViewById(R.id.filter_headert2)).setTextColor(headerText);

    ListView subList = (ListView) dialogView.findViewById(R.id.filter_subredditList);
    final SubsListAdapter filterSubsAdapter = new SubsListAdapter(SubredditSelectActivity.this, null);
    subList.setAdapter(filterSubsAdapter);

    AlertDialog.Builder builder = new AlertDialog.Builder(SubredditSelectActivity.this);
    builder.setView(dialogView).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override/*from   w w w. j ava  2 s  .c om*/
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
        }
    }).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
            global.getSubredditManager().setAllFilter(filterSubsAdapter.getSubsList());
            needsFeedUpdate = true; // mark feed for updating
        }
    }).show().getWindow().clearFlags(
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
}

From source file:com.microsoft.windowsazure.mobileservices.zumoe2etestapp.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.menu_settings:
        startActivity(new Intent(this, ZumoPreferenceActivity.class));
        return true;

    case R.id.menu_run_tests:
        if (getMobileServiceKey().trim() == "" || getMobileServiceURL().trim() == "") {
            startActivity(new Intent(this, ZumoPreferenceActivity.class));
        } else {/*  w ww  .  j  a  v  a2 s .  c  o  m*/
            runTests();
        }
        return true;

    case R.id.menu_check_all:
        changeCheckAllTests(true);
        return true;

    case R.id.menu_uncheck_all:
        changeCheckAllTests(false);
        return true;

    case R.id.menu_reset:
        refreshTestGroupsAndLog();
        return true;

    case R.id.menu_view_log:
        AlertDialog.Builder logDialogBuilder = new AlertDialog.Builder(this);
        logDialogBuilder.setTitle("Log");

        final WebView webView = new WebView(this);

        String logContent = TextUtils.htmlEncode(mLog.toString()).replace("\n", "<br />");
        String logHtml = "<html><body><pre>" + logContent + "</pre></body></html>";
        webView.loadData(logHtml, "text/html", "utf-8");

        logDialogBuilder.setPositiveButton("Copy", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                ClipboardManager clipboardManager = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                clipboardManager.setText(mLog.toString());
            }
        });

        logDialogBuilder.setView(webView);

        logDialogBuilder.create().show();
        return true;

    default:
        return super.onOptionsItemSelected(item);
    }
}

From source file:com.anp.bdmt.MainActivity.java

/**
 * ?  ?//from   w ww .ja  v a 2s .c o  m
 */
// private void httpRequestErrorMsg() {
// if (!isFinishing()) {
// // Util.showDialog(this, "", "? ?  . ? ? ? .",
// // null);
// }
// }

@Override
protected Dialog onCreateDialog(int i) {
    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);

    LayoutInflater inflater = MainActivity.this.getLayoutInflater();

    final View view = inflater.inflate(R.layout.dialog_custom_login, null);

    builder.setView(view);
    builder.setPositiveButton("login", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            EditText passwordEditText = (EditText) view.findViewById(R.id.password);
            // EditText distanceEditText = (EditText)
            // view.findViewById(R.id.distance);

            if (passwordEditText.getText().toString().equals("1599")) {
                adminFlag = true;
                Toast.makeText(mContext, "?", Toast.LENGTH_SHORT).show();
                // try {
                // sDistance =
                // Integer.parseInt(distanceEditText.getText().toString());
                // } catch (NumberFormatException e) {
                // e.printStackTrace();
                // sDistance = 3;
                // }
                // mManualTextView.setVisibility(View.VISIBLE);
            } else {
                adminFlag = false;
                sDistance = 3;
                // mManualTextView.setVisibility(View.GONE);
            }

        }
    });

    return builder.create();
}

From source file:com.agustinprats.myhrv.fragment.MonitorFragment.java

/** Displays help to the user. */
private void showHelp() {

    AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
    alert.setTitle(getActivity().getString(R.string.Help));

    WebView wv = new WebView(getActivity());

    // loading the html file
    String htmlData = readAsset("help.html");

    // selecting the css based on the activity theme
    //        htmlData = htmlData.replaceFirst("CSS_FILE_NAME", ((MainActivity) getActivity()).isLightTheme() ? "light" : "dark");
    htmlData = htmlData.replaceFirst("CSS_FILE_NAME", "dark");
    // loading html in the webview
    wv.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "UTF-8", null);

    wv.setWebViewClient(new WebViewClient() {
        @Override/*from  w w w. ja va  2  s  . c  om*/
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });

    alert.setView(wv);
    alert.setNegativeButton(getActivity().getString(R.string.Close), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();
        }
    });
    alert.show();
}

From source file:de.baumann.hhsmoodle.data_random.Random_Fragment.java

private void setRandomList() {

    if (isFABOpen) {
        closeFABMenu();/*from  w w w  .  j  a  v a 2s.c  o  m*/
    }

    //display data
    final int layoutstyle = R.layout.list_item_notes;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "random_title", "random_content", "random_creation" };
    final Cursor row = db.fetchAllData();
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), layoutstyle, row, column, xml_id, 0) {
        @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

            View v = super.getView(position, convertView, parent);
            ImageView iv_icon = (ImageView) v.findViewById(R.id.icon_notes);
            iv_icon.setVisibility(View.GONE);

            return v;
        }
    };

    lv.setAdapter(adapter);
    //onClick function
    lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String random_content = row2.getString(row2.getColumnIndexOrThrow("random_content"));
            final String random_title = row2.getString(row2.getColumnIndexOrThrow("random_title"));

            if (random_content.isEmpty()) {
                Snackbar.make(lv, getActivity().getString(R.string.number_enterData), Snackbar.LENGTH_LONG)
                        .show();
            } else {
                getActivity().setTitle(random_title);
                lv.setVisibility(View.GONE);
                lvItems.setVisibility(View.VISIBLE);

                try {
                    FileOutputStream fOut = new FileOutputStream(newFile());
                    OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
                    myOutWriter.append(random_content);
                    myOutWriter.close();

                    fOut.flush();
                    fOut.close();
                } catch (IOException e) {
                    Log.e("Exception", "File write failed: " + e.toString());
                }

                items = new ArrayList<>();
                readItems();

                setAdapter(1000);

                fab.setVisibility(View.GONE);
                fab_dice.setVisibility(View.VISIBLE);
            }
        }
    });

    lv.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            if (isFABOpen) {
                closeFABMenu();
            }

            Cursor row2 = (Cursor) lv.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String random_title = row2.getString(row2.getColumnIndexOrThrow("random_title"));
            final String random_content = row2.getString(row2.getColumnIndexOrThrow("random_content"));
            final String random_icon = row2.getString(row2.getColumnIndexOrThrow("random_icon"));
            final String random_attachment = row2.getString(row2.getColumnIndexOrThrow("random_attachment"));
            final String random_creation = row2.getString(row2.getColumnIndexOrThrow("random_creation"));

            final CharSequence[] options = { getString(R.string.number_edit_entry),
                    getString(R.string.bookmark_remove_bookmark) };
            new android.app.AlertDialog.Builder(getActivity())
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {

                            if (options[item].equals(getString(R.string.number_edit_entry))) {

                                android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(
                                        getActivity());
                                View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null);

                                final EditText edit_title = (EditText) dialogView
                                        .findViewById(R.id.note_title_input);
                                edit_title.setHint(R.string.title_hint);
                                edit_title.setText(random_title);

                                final EditText edit_cont = (EditText) dialogView
                                        .findViewById(R.id.note_text_input);
                                edit_cont.setHint(R.string.text_hint);
                                edit_cont.setText(random_content);

                                builder.setView(dialogView);
                                builder.setTitle(R.string.number_edit_entry);
                                builder.setPositiveButton(R.string.toast_yes,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {

                                                String inputTitle = edit_title.getText().toString().trim();
                                                String inputCont = edit_cont.getText().toString().trim();
                                                db.update(Integer.parseInt(_id), inputTitle, inputCont,
                                                        random_icon, random_attachment, random_creation);
                                                setRandomList();
                                                Snackbar.make(lv, R.string.bookmark_added,
                                                        Snackbar.LENGTH_SHORT).show();
                                            }
                                        });
                                builder.setNegativeButton(R.string.toast_cancel,
                                        new DialogInterface.OnClickListener() {

                                            public void onClick(DialogInterface dialog, int whichButton) {
                                                dialog.cancel();
                                            }
                                        });

                                final android.app.AlertDialog dialog2 = builder.create();
                                // Display the custom alert dialog on interface
                                dialog2.show();
                                helper_main.showKeyboard(getActivity(), edit_title);
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(lv, R.string.note_remove_confirmation, Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setRandomList();
                                            }
                                        });
                                snackbar.show();
                            }

                        }
                    }).show();

            return true;
        }
    });
}

From source file:com.bubblegum.traceratops.app.ui.fragments.LogFilterFragment.java

@NonNull
@Override/*ww  w  .  j a v  a2 s.  com*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext())
            .setPositiveButton(R.string.apply, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    applyFilters();
                }
            }).setNegativeButton(R.string.cancel, null)
            .setNeutralButton(R.string.clear_filters, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    clearFilters();
                }
            }).setTitle(R.string.filter_title);

    LayoutInflater inflater = getActivity().getLayoutInflater();
    View filterView = inflater.inflate(R.layout.fragment_log_filter, null);

    mLevelSeekbar = (SeekBar) filterView.findViewById(R.id.level_seekbar);
    mCrashSwitch = (Switch) filterView.findViewById(R.id.crash_switch);
    mTagTextTv = (TextView) filterView.findViewById(R.id.tag_tv);
    mTagValueEt = (EditText) filterView.findViewById(R.id.tag_value);
    mLogLevelIndicator = (TextView) filterView.findViewById(R.id.level_info_tv);
    setupSeekbar();
    mLevelSeekbar.setOnSeekBarChangeListener(this);
    mCrashSwitch.setOnCheckedChangeListener(this);

    prefillExistingFilters();

    builder.setView(filterView);
    return builder.create();
}

From source file:com.example.drugsformarinemammals.Dose_Information.java

private void displayMessage(String messageTitle, String message) {
    AlertDialog.Builder myalert = new AlertDialog.Builder(this);

    TextView title = new TextView(this);
    title.setTypeface(Typeface.SANS_SERIF);
    title.setTextSize(20);//  www. j a v a 2s  . c  o m
    title.setTextColor(getResources().getColor(R.color.blue));
    title.setPadding(8, 8, 8, 8);
    title.setText("Synchronization");
    title.setGravity(Gravity.CENTER_VERTICAL);

    LinearLayout layout = new LinearLayout(this);
    TextView text = new TextView(this);
    text.setTypeface(Typeface.SANS_SERIF);
    text.setTextSize(20);
    text.setPadding(10, 10, 10, 10);
    text.setText(message);
    layout.addView(text);

    myalert.setView(layout);
    myalert.setCustomTitle(title);
    myalert.setCancelable(true);
    myalert.show();

}