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.example.team04adventure.Controller.OnlineStoryList.java

/**
 * Starts a dialog box which allows the user to create a new story.
 * //from   ww w . j a va  2  s . co  m
 * @param view
 *            the current view.
 */
public void addStory(View view) {
    AlertDialog.Builder adb = new AlertDialog.Builder(this);
    LinearLayout lila1 = new LinearLayout(this);
    lila1.setOrientation(1);
    final EditText titleinput = new EditText(this);
    final EditText bodyinput = new EditText(this);
    titleinput.setHint("Enter the Title here.");
    bodyinput.setHint("Enter a Synopsis here.");
    lila1.addView(titleinput);
    lila1.addView(bodyinput);
    adb.setView(lila1);

    adb.setTitle("New Story");

    adb.setNegativeButton("Create", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            Story story = new Story();
            story.setTitle(titleinput.getText().toString());
            Random rg = new Random();
            int rint = rg.nextInt(100);
            story.setSynopsis(bodyinput.getText().toString());
            story.setId(story.getTitle().replace(" ", "") + rint);
            story.setAuthor(MainActivity.username);
            story.setVersion(1);

            StorageManager sm = new StorageManager(getBaseContext());

            sm.addStory(story);

            Intent intent = new Intent(OnlineStoryList.this, OnlineStoryList.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

            startActivity(intent);
        }
    });

    adb.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {

            return;
        }
    });

    adb.show();

}

From source file:com.duy.pascal.ui.editor.EditorActivity.java

/**
 * replace dialog find/*w  w w .  ja v a  2 s .com*/
 */
public void showDialogFind() {
    AlertDialog.Builder builder = new AlertDialog.Builder(EditorActivity.this);
    builder.setView(R.layout.dialog_find);
    final AlertDialog alertDialog = builder.create();
    alertDialog.show();
    final CheckBox ckbRegex = alertDialog.findViewById(R.id.ckb_regex);
    final CheckBox ckbMatch = alertDialog.findViewById(R.id.ckb_match_key);
    final CheckBox ckbWordOnly = alertDialog.findViewById(R.id.ckb_word_only);
    final EditText editFind = alertDialog.findViewById(R.id.txt_find);
    editFind.setText(getPreferences().getString(PascalPreferences.LAST_FIND));
    alertDialog.findViewById(R.id.btn_replace).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditorFragment editorFragment = mPagerAdapter.getCurrentFragment();
            if (editorFragment != null) {
                editorFragment.find(editFind.getText().toString(), ckbRegex.isChecked(),
                        ckbWordOnly.isChecked(), ckbMatch.isChecked());
            }
            getPreferences().put(PascalPreferences.LAST_FIND, editFind.getText().toString());
            alertDialog.dismiss();
        }
    });
    alertDialog.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            alertDialog.dismiss();
        }
    });
}

From source file:com.duy.pascal.ui.editor.EditorActivity.java

/**
 * create dialog find and replace//from w ww .  j a  va  2s .co  m
 */
@Override
public void findAndReplace() {
    AlertDialog.Builder builder = new AlertDialog.Builder(EditorActivity.this);
    builder.setView(R.layout.dialog_find_and_replace);
    final AlertDialog alertDialog = builder.create();
    alertDialog.show();

    final CheckBox ckbRegex = alertDialog.findViewById(R.id.ckb_regex);
    final CheckBox ckbMatch = alertDialog.findViewById(R.id.ckb_match_key);
    final EditText editFind = alertDialog.findViewById(R.id.txt_find);
    final EditText editReplace = alertDialog.findViewById(R.id.edit_replace);
    editFind.setText(getPreferences().getString(PascalPreferences.LAST_FIND));
    alertDialog.findViewById(R.id.btn_replace).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditorFragment editorFragment = mPagerAdapter.getCurrentFragment();
            if (editorFragment != null) {
                editorFragment.findAndReplace(editFind.getText().toString(), editReplace.getText().toString(),
                        ckbRegex.isChecked(), ckbMatch.isChecked());
            }
            getPreferences().put(PascalPreferences.LAST_FIND, editFind.getText().toString());
            alertDialog.dismiss();
        }
    });
    alertDialog.findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            alertDialog.dismiss();
        }
    });
}

From source file:com.example.spencerdepas.translationapp.activities.DMVStudyActivity.java

private void showSelectQuestionDialog() {
    Log.d(TAG, "showAlertDialog");
    // Prepare grid view
    GridView gridView = new GridView(this);

    int questionSize = driverQuestions.getQuestions().size();
    List<Integer> mList = new ArrayList<Integer>();
    for (int i = 1; i < questionSize + 1; i++) {
        mList.add(i);//from   w  w  w . ja va  2 s.  co  m
    }

    gridView.setAdapter(new ArrayAdapter<Integer>(this, R.layout.custom_list_item, mList) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);

            boolean hasBeenAnswered = hasBeenAnswered(position);
            Log.d(TAG, "hasBeenAnswered : " + hasBeenAnswered);
            int color = 0x00FFFFFF; // Transparent
            if (hasBeenAnswered) {

                if (driverQuestions.getQuestions().get(position).isAnsweredCorrectly()) {
                    //answer is correct
                    view.setBackgroundColor(getResources().getColor(R.color.colorForQuestionGrid));
                } else {
                    //answer is incorrect
                    view.setBackgroundColor(getResources().getColor(R.color.red));
                }

            } else {

                view.setBackgroundColor(color);
            }

            return view;
        }
    });
    gridView.setNumColumns(4);

    // Set grid view to alertDialog
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(gridView);
    builder.setTitle(getResources().getString(R.string.select_question));
    builder.setPositiveButton(getResources().getString(R.string.dialog_dismiss),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Log.d(TAG, getResources().getString(R.string.dialog_dismiss));
                    dialog.dismiss();
                }
            });

    final AlertDialog ad = builder.show();

    gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // do something here
            Log.d(TAG, "onclick");

            if (position == 0) {
                makePrevousButtonUnclickable();
            } else {
                makePrevousButtonClickable();
            }

            mNextButton.setText(getResources().getString(R.string.next_button));
            Log.d(TAG, "int pos : " + position);
            if (position == 193) {
                mNextButton.setText(getResources().getString(R.string.finish_studying));
            }

            goToSelectedQuestion(position);
            ad.dismiss();
        }
    });

}

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

private void showLoginDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(ViewRedditActivity.this);
    // Get the layout inflater
    LayoutInflater inflater = getLayoutInflater();
    final View v = inflater.inflate(R.layout.logindialog, null);

    builder.setView(v)
            // Add action buttons
            .setPositiveButton("Login", new DialogInterface.OnClickListener() {
                @Override//  w w  w  . jav  a  2  s.c om
                public void onClick(DialogInterface dialog, int id) {
                    final String username = ((EditText) v.findViewById(R.id.username)).getText().toString();
                    final String password = ((EditText) v.findViewById(R.id.password)).getText().toString();
                    final boolean rememberaccn = ((CheckBox) v.findViewById(R.id.rememberaccn)).isChecked();
                    dialog.cancel();
                    // run login procedure
                    final ProgressDialog logindialog = android.app.ProgressDialog.show(ViewRedditActivity.this,
                            "", ("Logging in..."), true);
                    Thread t = new Thread() {
                        public void run() {
                            // login
                            final String result = global.mRedditData.checkLogin(prefs, username, password,
                                    rememberaccn); // request "remember" cookie if account is being saved
                            // Set thread network policy to prevent network on main thread exceptions.
                            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll()
                                    .build();
                            StrictMode.setThreadPolicy(policy);
                            runOnUiThread(new Runnable() {
                                public void run() {
                                    logindialog.dismiss();
                                    if (result.equals("1")) {
                                        if (rememberaccn) { // store account if requested & login result is OK
                                            global.setAccount(prefs, username, password, true);
                                        }
                                    } else {
                                        // show error
                                        Toast.makeText(ViewRedditActivity.this, "Login error: " + result,
                                                Toast.LENGTH_LONG).show();
                                    }
                                }
                            });
                        }
                    };
                    t.start();
                }
            }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            }).setTitle("Login to Reddit");
    builder.create().show();
}

From source file:com.duy.pascal.ui.editor.EditorActivity.java

/**
 * show dialog with file info/*www.j a  v a 2s.c o m*/
 * filePath, path, size, extension ...
 *
 * @param file - file to show info
 */
private void showFileInfo(File file) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(file.getName());
    builder.setView(R.layout.dialog_view_file);
    AlertDialog dialog = builder.create();
    dialog.show();
    TextView txtInfo = dialog.findViewById(R.id.txt_info);
    txtInfo.setText(file.getPath());
    EditorView editorView = dialog.findViewById(R.id.editor_view);
    editorView.setTextHighlighted(mFileManager.fileToString(file));
}

From source file:cl.smartcities.isci.transportinspector.dialogs.BusSelectionDialog.java

@NonNull
@Override//from   w  w w .jav  a 2  s. c  o  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final AlertDialog dialog;
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());

    LayoutInflater inflater = this.getActivity().getLayoutInflater();
    final View dialog_view = inflater.inflate(R.layout.bus_selection_dialog, null);
    final Typeface iconTypeface = Typeface.createFromAsset(this.getContext().getAssets(),
            getActivity().getString(R.string.icon_font));
    ((TextView) dialog_view.findViewById(R.id.suggestion_icon)).setTypeface(iconTypeface);

    builder.setView(dialog_view);
    builder.setCancelable(false);
    dialog = builder.create();

    final Bundle bundle = getArguments();
    ArrayList<Bus> buses = null;

    if (bundle != null) {
        buses = bundle.getParcelableArrayList(NotificationState.BUSES);
    }

    if (buses != null && !buses.isEmpty()) {
        dialog_view.findViewById(R.id.list_view).setVisibility(View.VISIBLE);
        setBusMap(buses);
        ArrayList<String> serviceList = new ArrayList<>();
        serviceList.addAll(this.busMap.keySet());
        BusSelectionAdapter adapter = new BusSelectionAdapter(this.getContext(), serviceList, busMap,
                new BusSelectionAdapter.ListViewAdapterListener() {
                    @Override
                    public void onPositiveClick(Bus bus) {
                        dialog.cancel();
                        listener.onPositiveClick(bus);
                    }

                    @Override
                    public void onNegativeClick() {
                        dialog.cancel();
                        listener.onNegativeClick();
                    }
                });
        ListView listView = (ListView) dialog_view.findViewById(R.id.list_view);

        listView.setAdapter(adapter);

        if (adapter.getCount() > VISIBLE_BUSES) {
            View item = adapter.getView(0, null, listView);
            item.measure(0, 0);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.MATCH_PARENT,
                    (int) ((VISIBLE_BUSES + 0.5) * item.getMeasuredHeight()));
            listView.setLayoutParams(params);
        }

    }

    Button otherAcceptButton = (Button) dialog_view.findViewById(R.id.accept);
    otherAcceptButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            EditText serviceEditText = (EditText) dialog_view.findViewById(R.id.service_edit_text);
            EditText licensePlateEditText = (EditText) dialog_view.findViewById(R.id.license_plate_edit_text);
            String service = serviceEditText.getText().toString();
            String licensePlate = licensePlateEditText.getText().toString();
            ServiceHelper helper = new ServiceHelper(getContext());

            if (ServiceValidator.validate(service) && helper.getColorId(Util.formatServiceName(service)) != 0) {
                service = Util.formatServiceName(service);
                if (licensePlate.equals("")) {
                    licensePlate = Constants.DUMMY_LICENSE_PLATE;
                } else if (!LicensePlateValidator.validate(licensePlate)) {
                    Toast.makeText(getContext(), R.string.bus_selection_warning_plate, Toast.LENGTH_SHORT)
                            .show();
                    return;
                }
            } else {
                Toast.makeText(getContext(), R.string.bus_selection_warning_service, Toast.LENGTH_SHORT).show();
                return;
            }

            final Bus bus = new Bus(Util.formatServiceName(service), licensePlate);
            InputMethodManager imm = (InputMethodManager) getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);

            Log.d("BusSelectionDialog", "hiding soft input");

            Timer timer = new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    BusSelectionDialog.this.getActivity().runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            dialog.cancel();
                            listener.onPositiveClick(bus);
                        }
                    });
                }
            }, 500);
            //dialog.cancel();
            // TODO(aantoine): This call is to quick, some times the keyboard is not
            // out of the window when de sliding panel shows up.
            //listener.onPositiveClick(bus);
        }
    });

    /* set cancel button to close dialog */
    dialog_view.findViewById(R.id.close_dialog).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.cancel();
            listener.onNegativeClick();
        }
    });
    ((Button) dialog_view.findViewById(R.id.close_dialog)).setTypeface(iconTypeface);
    dialog.setCanceledOnTouchOutside(false);

    return dialog;
}

From source file:com.auth0.sample.ProfileActivity.java

public AlertDialog setEndpointURL(Context context) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    final EditText input = new EditText(ProfileActivity.this);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    lp.setMargins(50, 50, 50, 50);//from   ww w  . j  a  v a 2 s .  c o  m
    input.setLayoutParams(lp);

    builder.setView(input).setTitle("Set Endpoint URL").setPositiveButton("Set",
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (input.getText().toString() != "") {
                        editor.putString("ENDPOINT_URL", input.getText().toString());
                        editor.commit();
                        refresh_handler.postDelayed(refresh_runnable, 50000);
                    } else {
                        Toast.makeText(ProfileActivity.this, "Enter An Url", Toast.LENGTH_SHORT).show();
                    }
                }
            });

    return builder.show();
}

From source file:edu.missouri.niaaa.ema.activity.AdminManageActivity.java

private Dialog AdminPinSetDialog(Context context) {
    LayoutInflater inflater = LayoutInflater.from(context);
    final View textEntryView = inflater.inflate(R.layout.pin_input, null);
    TextView pinText = (TextView) textEntryView.findViewById(R.id.pin_text);
    pinText.setText(R.string.admin_set_msg);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setCancelable(false);/* w w  w  . j av a 2 s .  co m*/
    builder.setTitle(R.string.admin_set_title);
    builder.setView(textEntryView);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {

            EditText pinEdite = (EditText) textEntryView.findViewById(R.id.pin_edit);
            String pinStr = pinEdite.getText().toString();
            Utilities.Log("Pin Dialog", "pin String is " + pinStr);

            String data = null;
            try {
                data = Utilities.encryption("0000" + "," + "1" + "," + pinStr);
            } catch (Exception e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            /*            check network*/

            /*            prepare params for server*/
            HttpPost request = new HttpPost(Utilities.VALIDATE_ADDRESS);

            List<NameValuePair> params = new ArrayList<NameValuePair>();

            params.add(new BasicNameValuePair("data", data));

            //               //file_name
            //               params.add(new BasicNameValuePair("userID","0000"));
            //               //function
            //               params.add(new BasicNameValuePair("pre","1"));
            //               //data
            //               params.add(new BasicNameValuePair("password",pinStr));

            /*            check identity*/

            try {
                request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));

                HttpResponse response = new DefaultHttpClient().execute(request);
                if (response.getStatusLine().getStatusCode() == 200) {
                    String result = EntityUtils.toString(response.getEntity());
                    Log.d("~~~~~~~~~~http post result", result);

                    if (result.equals("AdminIsChecked")) {
                        //do nothing

                    } else if (result.equals("AdminPinIsInvalid")) {

                        imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
                        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

                        Toast.makeText(getApplicationContext(), R.string.input_apin_failed, Toast.LENGTH_SHORT)
                                .show();
                        finish();
                    } else {

                        imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
                        imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

                        Toast.makeText(getApplicationContext(), R.string.input_apin_error, Toast.LENGTH_SHORT)
                                .show();
                        finish();
                    }
                } else {
                    Toast.makeText(getApplicationContext(), R.string.input_apin_return, Toast.LENGTH_SHORT)
                            .show();
                    finish();
                }

            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();

                imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
                imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

                Toast.makeText(getApplicationContext(), R.string.input_apin_net_error, Toast.LENGTH_SHORT)
                        .show();
                ;
                finish();
            }

        }
    });

    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int whichButton) {

            imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN);
            imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

            finish();
        }
    });

    return builder.create();
}

From source file:com.fb.android.remindmap.parselogin.ParseLoginActivity.java

private void updatePhoneNumber(final ParseUser user) {
    AlertDialog.Builder phoneNumberDialog = new AlertDialog.Builder(this);
    phoneNumberDialog.setTitle("Phone Number").setMessage("Please enter a 10 digit phone number");

    final EditText phoneNumberInput = new EditText(this);
    if (user.get("phoneNumber") != null) {
        phoneNumberInput.setText(user.get("phoneNumber").toString());
    }//from  ww  w  .ja  v a 2 s.  co m
    phoneNumberInput.setInputType(InputType.TYPE_CLASS_PHONE);
    phoneNumberInput.setPadding(100, 0, 100, 25);
    phoneNumberDialog.setView(phoneNumberInput);

    phoneNumberDialog.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            user.put("phoneNumber", phoneNumberInput.getText().toString());
            user.pinInBackground("phoneNumber", new SaveCallback() {
                @Override
                public void done(ParseException e) {
                    if (e == null) {
                        user.saveEventually();
                    } else {
                        Toast.makeText(getApplicationContext(), "Error saving: " + e.getMessage(),
                                Toast.LENGTH_LONG).show();
                    }
                }
            });

            if (user.get("phoneNumber") == null) {
                Toast.makeText(getApplicationContext(), "Please enter a valid 10-digit phone number",
                        Toast.LENGTH_LONG).show();
                updatePhoneNumber(user);
            }
            if (user.get("phoneNumber") != null) {
                if (user.get("phoneNumber").toString().length() != 10) {
                    Toast.makeText(getApplicationContext(), "Please enter a valid 10-digit phone number",
                            Toast.LENGTH_LONG).show();
                    updatePhoneNumber(user);
                }
                if (user.get("phoneNumber").toString().length() == 10) {
                    finish();
                }
            }
        }
    })

            .setIcon(android.R.drawable.ic_menu_call).show();
}