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:com.androzic.About.java

@SuppressLint("InflateParams")
@Override/* w w w. ja  va  2s.c o  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(getString(R.string.app_name));
    View view = getActivity().getLayoutInflater().inflate(R.layout.dlg_about, null);
    builder.setView(view);
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            About.this.dismiss();
        }
    });
    updateAboutInfo(view);
    return builder.create();
}

From source file:br.pro.menotti.opus.pt.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    db = new SQLiteHelper(getApplicationContext());

    String listStr[] = getResources().getStringArray(R.array.listString);

    ListView lv = (ListView) findViewById(android.R.id.list);

    lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listStr));

    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override/*from   w w  w.j  av a2  s  .  c  o m*/
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            SQLiteHelper db;
            switch (position) {
            case 0:
                showBooks();
                break;
            case 1:
                AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext());
                builder.setTitle(R.string.display_search);

                final EditText input = new EditText(view.getContext());
                builder.setView(input);

                builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        String search_key = input.getEditableText().toString().trim();
                        if (!search_key.equals("")) {
                            showPoints(search_key);
                        }
                    }
                });
                AlertDialog alertDialog = builder.create();
                alertDialog.show();
                break;
            case 2:
                db = new SQLiteHelper(getBaseContext());
                db.openDataBase();
                showFavorites();
                db.close();
                break;
            case 3:
                db = new SQLiteHelper(getBaseContext());
                db.openDataBase();
                BookPoint bp = db.getBookPoint();
                DialogFragment newFragment = new DialogPoint(bp);
                newFragment.show(getSupportFragmentManager(), bp.toString());
                db.close();
                break;
            default:
                Toast.makeText(getApplicationContext(), ((TextView) view).getText(), Toast.LENGTH_SHORT).show();
            }
        }

    });

    try {

        db.createDataBase();

    } catch (IOException ioe) {

        throw new Error("Unable to create database");

    }

    try {

        db.openDataBase();
        db.close();

    } catch (SQLException sqle) {

        throw sqle;

    }
}

From source file:com.anjalimacwan.fragment.dialog.AboutDialogFragment.java

@NonNull
@Override//from ww  w.j  av a  2 s  .  c om
public Dialog onCreateDialog(Bundle savedInstanceState) {

    // Use the Builder class for convenient dialog construction
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    // Get the layout inflater
    final LayoutInflater inflater = getActivity().getLayoutInflater();

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    final View view = inflater.inflate(R.layout.fragment_dialogs, null);

    builder.setView(view).setTitle(R.string.dialog_about_title).setPositiveButton(R.string.action_close, null);

    textView = (TextView) view.findViewById(R.id.dialogMessage);
    textView.setText(R.string.dialog_about_message);
    textView.setMovementMethod(LinkMovementMethod.getInstance());

    // Create the AlertDialog object and return it
    return builder.create();
}

From source file:dtu.ds.warnme.app.dialog.ReportDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_report, null);
    builder.setView(view);
    builder.setTitle(R.string.report);/*from  w ww .  jav  a 2s.co  m*/
    builder.setPositiveButton(R.string.report, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int which) {
            // Nothing do to here
        }
    });

    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int which) {
            // Nothing do to here
        }
    });

    progressView = view.findViewById(R.id.dialog_report_progress);
    formView = view.findViewById(R.id.dialog_report_form);

    accidentRdBtn = (RadioButton) view.findViewById(R.id.dialog_report_form_radio_button_event_type_accident);
    policeRdBtn = (RadioButton) view.findViewById(R.id.dialog_report_form_radio_button_event_type_police);
    speedCameraRdBtn = (RadioButton) view
            .findViewById(R.id.dialog_report_form_radio_button_event_type_speed_camera);
    noteEditText = (EditText) view.findViewById(R.id.dialog_report_form_edit_text_note);

    dialog = builder.create();

    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialogInterface) {

            final Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            positiveButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    String note = noteEditText.getText().toString();
                    Location location = (Location) getArguments().get(MainActivity.KEY_CURRENT_LOCATION);

                    Event event = new Event();
                    event.setEventType(getEventType());
                    event.setLatitude(location.getLatitude());
                    event.setLongitude(location.getLongitude());
                    event.setBearing((180 + location.getBearing()) % 360);
                    event.setNote(note);

                    RestClientHolder.getRestClient().addEvent(dialog.getContext(), event,
                            new AsyncHttpResponseHandler() {

                                @Override
                                public void onFailure(int statusCode, Header[] headers, byte[] responseBody,
                                        Throwable error) {
                                    Log.e(TAG, "Reporting failed. [statusCode = " + statusCode + ", error="
                                            + error + "]");
                                    listener.onReportFailed();

                                    Toast.makeText(dialog.getContext(), R.string.report_failed,
                                            Toast.LENGTH_LONG).show();
                                }

                                @Override
                                public void onFinish() {
                                    positiveButton.setEnabled(true);
                                    UiUtilities.fadeInFadeOut(formView, progressView);
                                }

                                @Override
                                public void onStart() {
                                    positiveButton.setEnabled(false);
                                    UiUtilities.fadeInFadeOut(progressView, formView);
                                }

                                @Override
                                public void onSuccess(int statusCode, Header[] headers, byte[] responseBody) {
                                    Log.i(TAG, "Reporting successful. [statusCode = " + statusCode + "]");
                                    dialog.dismiss();

                                    listener.onReportSuccessful();
                                }

                            });

                }
            });

            final Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE);
            negativeButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    RestClientHolder.getRestClient().cancelRequests(dialog.getOwnerActivity(), true);
                    dialog.dismiss();
                    listener.onAbort();
                }
            });

        }
    });

    return dialog;
}

From source file:com.Duo.music.player.Dialogs.CustomizeScreensDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    parentActivity = getActivity();// w  ww.  j  av  a  2  s .c o  m
    dialogFragment = (DialogFragment) getFragmentManager().findFragmentByTag("customizeScreensDialog");

    sharedPreferences = parentActivity.getSharedPreferences("com.jams.music.player", Context.MODE_PRIVATE);

    rootView = (View) parentActivity.getLayoutInflater().inflate(R.layout.customize_screens_layout, null);

    customizeScreensText = (TextView) rootView.findViewById(R.id.customize_screens_text);
    customizeScreensText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    customizeScreensText.setPaintFlags(
            customizeScreensText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    //Populate the arraylists with the settings saved in SharedPreferences.
    page1 = sharedPreferences.getString("PAGE_1", getResources().getString(R.string.artists_caps));
    page2 = sharedPreferences.getString("PAGE_2", getResources().getString(R.string.albums_caps));
    page3 = sharedPreferences.getString("PAGE_3", getResources().getString(R.string.songs_caps));
    page4 = sharedPreferences.getString("PAGE_4", getResources().getString(R.string.playlists_caps));
    page5 = sharedPreferences.getString("PAGE_5", getResources().getString(R.string.genres_caps));
    page6 = sharedPreferences.getString("PAGE_6", getResources().getString(R.string.folders_caps));

    if (!page1.equals("null") || !page1.equals(null)) {
        screenTitlesList.add(page1);
    }

    if (!page2.equals("null") || !page2.equals(null)) {
        screenTitlesList.add(page2);
    }

    if (!page3.equals("null") || !page3.equals(null)) {
        screenTitlesList.add(page3);
    }

    if (!page4.equals("null") || !page4.equals(null)) {
        screenTitlesList.add(page4);
    }

    if (!page5.equals("null") || !page5.equals(null)) {
        screenTitlesList.add(page5);
    }

    if (!page6.equals("null") || !page6.equals(null)) {
        screenTitlesList.add(page6);
    }

    listView = (DragSortListView) rootView.findViewById(R.id.customize_screens_listview);
    adapter = new CustomizeScreensListAdapter(parentActivity, screenTitlesList);
    listView.setAdapter(adapter);
    listView.setDropListener(onDrop);
    SimpleFloatViewManager simpleFloatViewManager = new SimpleFloatViewManager(listView);
    simpleFloatViewManager.setBackgroundColor(Color.TRANSPARENT);
    listView.setFloatViewManager(simpleFloatViewManager);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    //Set the dialog title.
    builder.setTitle(R.string.customize_screens);
    builder.setView(rootView);
    builder.setPositiveButton(R.string.done, new OnClickListener() {

        @Override
        public void onClick(DialogInterface arg0, int arg1) {
            dialogFragment.dismiss();

            //adapter.getItem(i) will get us the order for the screens.
            sharedPreferences.edit().putString("PAGE_1", adapter.getItem(0).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_2", adapter.getItem(1).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_3", adapter.getItem(2).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_4", adapter.getItem(3).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_5", adapter.getItem(4).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_6", adapter.getItem(5).toString().toUpperCase()).commit();

            Toast.makeText(parentActivity, R.string.changes_saved, Toast.LENGTH_SHORT).show();

            //Restart the app.
            Intent i = parentActivity.getBaseContext().getPackageManager()
                    .getLaunchIntentForPackage(parentActivity.getBaseContext().getPackageName());

            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            dialogFragment.dismiss();
            getActivity().finish();
            startActivity(i);

        }

    });

    return builder.create();
}

From source file:com.esri.arcgisruntime.sample.hillshaderenderer.ParametersDialogFragment.java

/**
 * Builds a parameter dialog box with values pulled through from MainActivity.
 * @param savedInstanceState bundle holding previous activity's saved state
 * @return create parameter dialog box//  w  w  w .j  a  va2s .  c om
 */
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    Bundle hillshadeParameters = getArguments();
    if (hillshadeParameters != null) {
        mAltitude = hillshadeParameters.getInt("altitude");
        mAzimuth = hillshadeParameters.getInt("azimuth");
        mSlopeType = (SlopeType) hillshadeParameters.getSerializable("slope_type");
    }

    AlertDialog.Builder paramDialog = new AlertDialog.Builder(getContext());
    @SuppressLint("InflateParams")
    View dialogView = inflater.inflate(R.layout.hillshade_dialog_box, null);
    paramDialog.setView(dialogView);
    paramDialog.setTitle(R.string.dialog_title);
    paramDialog.setNegativeButton("Cancel", (dialog, which) -> dismiss());
    paramDialog.setPositiveButton("Render", (dialog, which) -> {
        ParametersListener activity = (ParametersListener) getActivity();
        activity.returnParameters(mAltitude, mAzimuth, mSlopeType);
    });

    mCurrAltitudeTextView = dialogView.findViewById(R.id.hillshade_curr_altitude_text);
    SeekBar altitudeSeekBar = dialogView.findViewById(R.id.hillshade_altitude_seek_bar);
    altitudeSeekBar.setMax(90); //altitude is restricted to 0 - 90
    //set initial altitude value
    updateAltitudeSeekBar(altitudeSeekBar);
    altitudeSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mAltitude = progress;
            updateAltitudeSeekBar(seekBar);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    mCurrAzimuthTextView = dialogView.findViewById(R.id.hillshade_curr_azimuth_text);
    SeekBar azimuthSeekBar = dialogView.findViewById(R.id.hillshade_azimuth_seek_bar);
    azimuthSeekBar.setMax(360); //azimuth measured in degrees 0 - 360
    //set initial azimuth value
    updateAzimuthSeekBar(azimuthSeekBar);
    azimuthSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            mAzimuth = progress;
            updateAzimuthSeekBar(seekBar);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    List<String> slopeTypeArray = new ArrayList<>();
    slopeTypeArray.add("None"); //ordinals:0
    slopeTypeArray.add("Degree"); //1
    slopeTypeArray.add("Percent rise"); //2
    slopeTypeArray.add("Scaled"); //3

    ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(), R.layout.hillshade_spinner_text_view,
            slopeTypeArray);

    Spinner slopeTypeSpinner = dialogView.findViewById(R.id.hillshade_slope_type_spinner);
    slopeTypeSpinner.setAdapter(spinnerAdapter);
    slopeTypeSpinner.setSelection(mSlopeType.ordinal());
    slopeTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            switch (position) {
            case 0:
                mSlopeType = SlopeType.NONE;
                break;
            case 1:
                mSlopeType = SlopeType.DEGREE;
                break;
            case 2:
                mSlopeType = SlopeType.PERCENT_RISE;
                break;
            case 3:
                mSlopeType = SlopeType.SCALED;
                break;
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });

    return paramDialog.create();
}

From source file:com.aniruddhc.acemusic.player.Dialogs.CustomizeScreensDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    parentActivity = getActivity();/*from w w  w  .ja  va2s .  c o m*/
    dialogFragment = (DialogFragment) getFragmentManager().findFragmentByTag("customizeScreensDialog");

    sharedPreferences = parentActivity.getSharedPreferences("com.aniruddhc.acemusic.player",
            Context.MODE_PRIVATE);

    rootView = (View) parentActivity.getLayoutInflater().inflate(R.layout.customize_screens_layout, null);

    customizeScreensText = (TextView) rootView.findViewById(R.id.customize_screens_text);
    customizeScreensText.setTypeface(TypefaceHelper.getTypeface(parentActivity, "RobotoCondensed-Light"));
    customizeScreensText.setPaintFlags(
            customizeScreensText.getPaintFlags() | Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG);

    //Populate the arraylists with the settings saved in SharedPreferences.
    page1 = sharedPreferences.getString("PAGE_1", getResources().getString(R.string.artists_caps));
    page2 = sharedPreferences.getString("PAGE_2", getResources().getString(R.string.albums_caps));
    page3 = sharedPreferences.getString("PAGE_3", getResources().getString(R.string.songs_caps));
    page4 = sharedPreferences.getString("PAGE_4", getResources().getString(R.string.playlists_caps));
    page5 = sharedPreferences.getString("PAGE_5", getResources().getString(R.string.genres_caps));
    page6 = sharedPreferences.getString("PAGE_6", getResources().getString(R.string.folders_caps));

    if (!page1.equals("null") || !page1.equals(null)) {
        screenTitlesList.add(page1);
    }

    if (!page2.equals("null") || !page2.equals(null)) {
        screenTitlesList.add(page2);
    }

    if (!page3.equals("null") || !page3.equals(null)) {
        screenTitlesList.add(page3);
    }

    if (!page4.equals("null") || !page4.equals(null)) {
        screenTitlesList.add(page4);
    }

    if (!page5.equals("null") || !page5.equals(null)) {
        screenTitlesList.add(page5);
    }

    if (!page6.equals("null") || !page6.equals(null)) {
        screenTitlesList.add(page6);
    }

    listView = (DragSortListView) rootView.findViewById(R.id.customize_screens_listview);
    adapter = new CustomizeScreensListAdapter(parentActivity, screenTitlesList);
    listView.setAdapter(adapter);
    listView.setDropListener(onDrop);
    SimpleFloatViewManager simpleFloatViewManager = new SimpleFloatViewManager(listView);
    simpleFloatViewManager.setBackgroundColor(Color.TRANSPARENT);
    listView.setFloatViewManager(simpleFloatViewManager);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    //Set the dialog title.
    builder.setTitle(R.string.customize_screens);
    builder.setView(rootView);
    builder.setPositiveButton(R.string.done, new OnClickListener() {

        @Override
        public void onClick(DialogInterface arg0, int arg1) {
            dialogFragment.dismiss();

            //adapter.getItem(i) will get us the order for the screens.
            sharedPreferences.edit().putString("PAGE_1", adapter.getItem(0).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_2", adapter.getItem(1).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_3", adapter.getItem(2).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_4", adapter.getItem(3).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_5", adapter.getItem(4).toString().toUpperCase()).commit();
            sharedPreferences.edit().putString("PAGE_6", adapter.getItem(5).toString().toUpperCase()).commit();

            Toast.makeText(parentActivity, R.string.changes_saved, Toast.LENGTH_SHORT).show();

            //Restart the app.
            Intent i = parentActivity.getBaseContext().getPackageManager()
                    .getLaunchIntentForPackage(parentActivity.getBaseContext().getPackageName());

            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            dialogFragment.dismiss();
            getActivity().finish();
            startActivity(i);

        }

    });

    return builder.create();
}

From source file:com.example.flashcards.wizardpager.wizard.ui.TopicChoiceFragment.java

private void getNewTopicName() {

    AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());

    alert.setTitle("Vlote sekci");
    alert.setMessage("Jmno");

    // Set an EditText view to get user input
    final EditText input = new EditText(getActivity());
    alert.setView(input);

    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            String value = input.getText().toString();
            createNewTopic(value);/*  ww  w .  j  a  v a 2 s.  c o m*/
        }

    });

    alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            // Canceled.
        }
    });

    alert.show();
}

From source file:com.android.settings.profiles.ProfilesSettings.java

private void addProfile() {
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View content = inflater.inflate(R.layout.profile_name_dialog, null);
    final TextView prompt = (TextView) content.findViewById(R.id.prompt);
    final EditText entry = (EditText) content.findViewById(R.id.name);

    prompt.setText(R.string.profile_profile_name_prompt);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(R.string.menu_new_profile);
    builder.setView(content);

    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override//from   w  w  w  .  jav  a2  s  . c om
        public void onClick(DialogInterface dialog, int which) {
            String name = entry.getText().toString();
            if (!mProfileManager.profileExists(name)) {
                Profile profile = new Profile(name);
                mProfileManager.addProfile(profile);
                mAdapter.refreshProfiles();
            } else {
                Toast.makeText(getActivity(), R.string.duplicate_profile_name, Toast.LENGTH_LONG).show();
            }
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);

    AlertDialog dialog = builder.create();
    dialog.show();
}

From source file:com.coinprism.wallet.ProgressDialog.java

@android.support.annotation.NonNull
@Override// w  w w  . j av  a2 s  .  c  om
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();

    View view = inflater.inflate(R.layout.dialog_progress, null);
    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder.setView(view);
    if (canCancel) {
        builder.setNegativeButton(getString(android.R.string.cancel), new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                ProgressDialog.this.getDialog().cancel();
                isCancelled = true;
            }
        });
    }

    Dialog result = builder.create();
    result.setTitle(this.title);

    TextView text = (TextView) view.findViewById(R.id.dialogContent);
    text.setText(this.content);

    return result;
}