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:ca.ualberta.cmput301.t03.user.FriendsListFragment.java

/**
 * Creates a new AlertDialog which can be
 * used to add friends./*www  .  j a  v  a2s. co m*/
 * <p>
 * The alertDialog contains a single EditText
 * where the user can enter the username to be
 * added.
 *
 * @return the configured AlertDialog
 */
private AlertDialog createAddFriendDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());
    View dialogContent = View.inflate(getContext(), R.layout.content_add_friend_dialog, null);
    final EditText e = (EditText) dialogContent.findViewById(R.id.addFriendEditText);

    builder.setView(dialogContent); //todo replace with layout
    builder.setCancelable(false);
    builder.setNegativeButton("Cancel", null);
    builder.setPositiveButton("Add", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final String usr = e.getText().toString().trim();

            AsyncTask t = new AsyncTask() {
                @Override
                protected Object doInBackground(Object[] params) {

                    if (usr.equals(""))
                        return null;
                    try {
                        mController.addFriend(usr);
                    } catch (IOException e1) {
                        Snackbar.make(getView(), "There was a problem with the network", Snackbar.LENGTH_SHORT);
                    } catch (UserNotFoundException e2) {
                        Snackbar.make(getView(), String.format("User %s does not exist", usr),
                                Snackbar.LENGTH_SHORT).show();
                    } catch (UserAlreadyAddedException e1) {
                        Snackbar.make(getView(), String.format("User %s is already added!", usr),
                                Snackbar.LENGTH_SHORT).show();
                    } catch (ServiceNotAvailableException e1) {
                        Snackbar.make(getView(), "You must be online to add friends!", Snackbar.LENGTH_SHORT)
                                .show();
                    }
                    return null;
                }
            };
            t.execute();
        }
    });
    builder.setTitle("Add a Friend");
    AlertDialog d = builder.create();
    return d;
}

From source file:com.apotheosis.acceleration.monitor.MainMenuActivity.java

private void initRecorderFragment() {
    if (getSupportActionBar() != null) {
        if (collector == null || !collector.isRunning())
            getSupportActionBar().setTitle("Data Collection Not Running");
        else/*from w  ww .j av a2s.com*/
            getSupportActionBar().setTitle("Data Collection In Progress");
    }

    pauseAccel = (Button) findViewById(R.id.pauseSensor);
    pauseAccel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (collector == null)
                collector = new DataCollector(MainMenuActivity.this);

            if (!collector.isRunning()) {
                AlertDialog.Builder filename = new AlertDialog.Builder(MainMenuActivity.this);
                filename.setTitle("Enter Filename: ");
                final EditText name = new EditText(MainMenuActivity.this);
                filename.setView(name);

                filename.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        if (!name.getText().toString().equalsIgnoreCase("")) {
                            if (!FileUtilities.fileExists(name.getText().toString())) {
                                dialog.dismiss();
                                startCollection(name.getText().toString());
                            }
                        }
                    }
                });
                filename.show();
            } else {
                stopCollection();
            }
        }
    });
}

From source file:com.example.sujit.myapplication.Get_Taxi.java

private void showDialog(double distance) {

    String dis = String.valueOf((int) distance);

    LayoutInflater li = LayoutInflater.from(this);
    //Creating a view to get the dialog box
    View confirmDialog = li.inflate(R.layout.dialog_distance, null);

    //Initizliaing confirm button fo dialog box and edit text of dialog box
    buttonSelect = (AppCompatButton) confirmDialog.findViewById(R.id.buttonSelect);
    buttonAssign = (AppCompatButton) confirmDialog.findViewById(R.id.buttonAssign);

    textView1 = (TextView) confirmDialog.findViewById(R.id.textView1);
    textView2 = (TextView) confirmDialog.findViewById(R.id.textView2);

    textView1.setText(dis);//from w  w w . j  ava 2s .  c  o  m
    //textView2.setText(time);

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

    //Adding our dialog box to the view of alert dialog
    alert.setView(confirmDialog);

    //Creating an alert dialog
    final AlertDialog alertDialog = alert.create();

    //Displaying the alert dialog
    alertDialog.show();

    buttonSelect.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            alertDialog.dismiss();
            getDrivers();
        }
    });
    buttonAssign.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            alertDialog.dismiss();
            showProfile();
        }
    });
}

From source file:com.airk.interpolatordiagram.app.fragment.AboutFragmentDialog.java

@NonNull
@Override//from   www . j  av a  2  s  .c  o m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setPositiveButton(android.R.string.ok, null);
    View v = LayoutInflater.from(getActivity()).inflate(R.layout.about_fragment, null);
    ButterKnife.inject(this, v);
    try {
        String version = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(),
                0).versionName;
        mVersion.setText("v" + version);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    builder.setView(v);
    return builder.create();
}

From source file:com.dsi.ant.antplus.pluginsampler.geocache.Dialog_GeoRequestAuthToken.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());

    builder.setTitle("Auth Token Request");
    // Get the layout inflater
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View detailsView = inflater.inflate(R.layout.dialog_geocache_reqauthtoken, null);

    // Inflate and set the layout for the dialog
    // Pass null as the parent view because its going in the dialog layout
    builder.setView(detailsView);

    // Add action buttons
    //Note we override the positive button in show() below so we can prevent it from closing
    builder.setPositiveButton("Request Token", null);
    builder.setNegativeButton("Back", new DialogInterface.OnClickListener() {
        @Override/* ww  w .  ja v a 2s.  c o  m*/
        public void onClick(DialogInterface dialog, int which) {
            //Let dialog dismiss
        }
    });

    editText_Nonce = (EditText) detailsView.findViewById(R.id.editText_Nonce);
    editText_SerialNumber = (EditText) detailsView.findViewById(R.id.editText_SerialNumber);
    textView_Status = (TextView) detailsView.findViewById(R.id.textView_Status);

    Random r = new Random();
    editText_Nonce.setText(String.valueOf(r.nextInt(65535)));
    editText_SerialNumber.setText(String.valueOf(requestingDeviceSerialNum));

    return builder.create();
}

From source file:adventure_fragments.Running.java

public void AddItemNow() {
    final EditText input;

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Add item to list");
    input = new EditText(getActivity());
    int maxLength = 20;
    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });

    builder.setView(input);
    builder.setPositiveButton("Add item", new DialogInterface.OnClickListener() {
        @Override/*from   w w w  .j ava  2 s. c o  m*/
        public void onClick(DialogInterface dialog, int which) {
            String item_name = input.getText().toString();

            if (item_name.equals("")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals(" ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("  ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("This app sucks")) {
                Toast.makeText(getActivity(), "No it doesn't!", Toast.LENGTH_SHORT).show();
            } else {

                ItemClass itemClass = new ItemClass(item_name, 0);
                db.addItemRunning(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsRunning();
                adapt = new CustomAdapter4(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_run);
                listItem.setAdapter(adapt);
                count = listItem.getCount();
                if (count > 0) {
                    nothingtext.setVisibility(View.GONE);
                } else if (count == 0) {
                    nothingtext.setVisibility(View.VISIBLE);
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.show();
}

From source file:adventure_fragments.Hiking.java

public void AddItemNow() {
    final EditText input;

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Add item to list");
    input = new EditText(getActivity());
    int maxLength = 20;
    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });

    builder.setView(input);
    builder.setPositiveButton("Add item", new DialogInterface.OnClickListener() {
        @Override// ww  w .j av a2 s.co  m
        public void onClick(DialogInterface dialog, int which) {
            String item_name = input.getText().toString();

            if (item_name.equals("")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals(" ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("  ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("This app sucks")) {
                Toast.makeText(getActivity(), "No it doesn't!", Toast.LENGTH_SHORT).show();
            } else {

                ItemClass itemClass = new ItemClass(item_name, 0);
                db.addItemHiking(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsHiking();
                adapt = new CustomAdapter2(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_hike);
                listItem.setAdapter(adapt);

                count = listItem.getCount();
                if (count > 0) {
                    nothingtext.setVisibility(View.GONE);
                } else if (count == 0) {
                    nothingtext.setVisibility(View.VISIBLE);
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.show();
}

From source file:adventure_fragments.Kayaking.java

public void AddItemNow() {
    final EditText input;

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Add item to list");
    input = new EditText(getActivity());
    int maxLength = 20;
    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });

    builder.setView(input);
    builder.setPositiveButton("Add item", new DialogInterface.OnClickListener() {
        @Override//from  w w  w  . j  a  v a2s. c  om
        public void onClick(DialogInterface dialog, int which) {
            String item_name = input.getText().toString();

            if (item_name.equals("")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals(" ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("  ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("This app sucks")) {
                Toast.makeText(getActivity(), "No it doesn't!", Toast.LENGTH_SHORT).show();
            } else {

                ItemClass itemClass = new ItemClass(item_name, 0);
                db.addItemKayaking(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsKayaking();
                adapt = new CustomAdapter3(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_kayak);
                listItem.setAdapter(adapt);
                count = listItem.getCount();
                if (count > 0) {
                    nothingtext.setVisibility(View.GONE);
                } else if (count == 0) {
                    nothingtext.setVisibility(View.VISIBLE);
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    builder.show();
}

From source file:adventure_fragments.Skiing.java

public void AddItemNow() {
    final EditText input;

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Add item to list");
    input = new EditText(getActivity());
    int maxLength = 20;
    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });

    builder.setView(input);
    builder.setPositiveButton("Add item", new DialogInterface.OnClickListener() {
        @Override// ww w .j ava 2 s .  com
        public void onClick(DialogInterface dialog, int which) {
            String item_name = input.getText().toString();

            if (item_name.equals("")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals(" ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("  ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("This app sucks")) {
                Toast.makeText(getActivity(), "No it doesn't!", Toast.LENGTH_SHORT).show();
            } else {

                ItemClass itemClass = new ItemClass(item_name, 0);
                db.addItemSkiing(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsSkiing();
                adapt = new CustomAdapter5(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_ski);
                listItem.setAdapter(adapt);
                count = listItem.getCount();
                if (count > 0) {
                    nothingtext.setVisibility(View.GONE);
                } else if (count == 0) {
                    nothingtext.setVisibility(View.VISIBLE);
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.show();
}

From source file:adventure_fragments.Swimming.java

public void AddItemNow() {
    final EditText input;

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Add item to list");
    input = new EditText(getActivity());
    int maxLength = 20;
    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });

    builder.setView(input);
    builder.setPositiveButton("Add item", new DialogInterface.OnClickListener() {
        @Override/* ww  w . j  a v  a2 s  .  c  o m*/
        public void onClick(DialogInterface dialog, int which) {
            String item_name = input.getText().toString();

            if (item_name.equals("")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals(" ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("  ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("This app sucks")) {
                Toast.makeText(getActivity(), "No it doesn't!", Toast.LENGTH_SHORT).show();
            } else {

                ItemClass itemClass = new ItemClass(item_name, 0);
                db.addItemSwimming(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsSwimming();
                adapt = new CustomAdapter6(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_swim);
                listItem.setAdapter(adapt);
                nothingtext = (TextView) rootView.findViewById(R.id.nothing_here_swim);
                count = listItem.getCount();
                if (count > 0) {
                    nothingtext.setVisibility(View.GONE);
                } else if (count == 0) {
                    nothingtext.setVisibility(View.VISIBLE);
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.show();
}