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:adventure_fragments.Climbing.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//  w ww. 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.addItemClimbing(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsClimbing();
                adapt = new CustomAdapter1(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_climb);
                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) {
            list = db.getAllItemsClimbing();
            adapt = new CustomAdapter1(getActivity(), R.layout.item_layout, list);
            listItem = (ListView) getActivity().findViewById(R.id.listview_climb);
            listItem.setAdapter(adapt);

            dialog.dismiss();
        }
    });

    builder.show();
}

From source file:com.androidhacks7.apprtc_android.RegistrationActivity.java

private void showUserDialog(int type, final Object... args) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    if (type == AppConstants.DIALOG_USERNAME) {
        builder.setMessage("Enter User Name: ");
        userName = new EditText(this);
        RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
        userName.setLayoutParams(lp);/*from   w ww .  java  2 s.c  o m*/
        builder.setView(userName);
        builder.setPositiveButton("Enter", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                register();
            }
        });
        builder.setNegativeButton("Quit", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                finish();
            }
        });
    } else if (type == 1) {
        try {
            final JSONObject jsonObject = new JSONObject(args[0].toString());
            builder.setMessage("Incoming call from " + jsonObject.get(JSONConstants.CALLER));
            builder.setPositiveButton("Attend", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Intent intent = new Intent(RegistrationActivity.this, VideoCallActivity.class);
                    intent.putExtra(JSONConstants.CALL_PARAMS, args[0].toString());
                    startActivity(intent);
                    finish();
                }
            });
            builder.setNegativeButton("Decline", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Intent intent = new Intent(RegistrationActivity.this, VideoCallActivity.class);
                    intent.putExtra(JSONConstants.CALL_PARAMS, args[0].toString());
                    intent.putExtra(JSONConstants.REJECT_CALL, args[0].toString());
                    startActivity(intent);
                }
            });
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    builder.create().show();
}

From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.FeedActionsFragment.java

public void broadcastGps() {
    final CharSequence[] items = { "5 minutes", "15 minutes", "1 hour", " 24 hours" };

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Choose duration of broadcast");
    builder.setItems(items, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, final int item) {
            AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
            alert.setMessage("Enter a secret key if you want to:");
            final EditText input = new EditText(getActivity());
            alert.setView(input);
            alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    final String password = input.getText().toString();
                    myLocation = new MyLocation();
                    locationResult = new MyLocation.LocationResult() {
                        final ProgressDialog dialog = ProgressDialog.show(getActivity(), "",
                                "Preparing broadcast...", true);

                        @Override
                        public void gotLocation(final Location location) {
                            //Got the location!
                            try {
                                int minutes;
                                if (item == 0) {
                                    minutes = 5;
                                } else if (item == 1) {
                                    minutes = 15;
                                } else if (item == 2) {
                                    minutes = 60;
                                } else if (item == 3) {
                                    minutes = 1440;
                                } else {
                                    minutes = 5;
                                }//from   www .  jav  a  2s . c o  m

                                Uri uri = new Uri.Builder().scheme("http").authority("suif.stanford.edu")
                                        .path("dungbeetle/nearby.php").build();

                                StringBuffer sb = new StringBuffer();
                                DefaultHttpClient client = new DefaultHttpClient();
                                HttpPost httpPost = new HttpPost(uri.toString());

                                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                                nameValuePairs.add(new BasicNameValuePair("group_name", mGroupName));
                                nameValuePairs
                                        .add(new BasicNameValuePair("feed_uri", mExternalFeedUri.toString()));
                                nameValuePairs.add(new BasicNameValuePair("length", Integer.toString(minutes)));
                                nameValuePairs.add(
                                        new BasicNameValuePair("lat", Double.toString(location.getLatitude())));
                                nameValuePairs.add(new BasicNameValuePair("lng",
                                        Double.toString(location.getLongitude())));
                                nameValuePairs.add(new BasicNameValuePair("password", password));
                                httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                                try {
                                    HttpResponse execute = client.execute(httpPost);
                                    InputStream content = execute.getEntity().getContent();
                                    BufferedReader buffer = new BufferedReader(new InputStreamReader(content));
                                    String s = "";
                                    while ((s = buffer.readLine()) != null) {
                                        sb.append(s);
                                    }
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }

                                String response = sb.toString();
                                if (response.equals("1")) {
                                    Toast.makeText(getActivity(), "Now broadcasting for " + items[item],
                                            Toast.LENGTH_SHORT).show();
                                } else
                                    Log.w(TAG, "Wtf");

                                Log.w(TAG, "response: " + response);
                            } catch (Exception e) {
                            }

                            dialog.dismiss();
                        }
                    };
                    locationClick();
                }
            });
            alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                }
            });
            alert.show();
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:ca.zadrox.dota2esportticker.ui.MatchActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Intent intentx;//  w ww .j a  va2 s.  co  m
    switch (item.getItemId()) {
    case R.id.menu_refresh:
        setRefreshingState(true);
        onRefresh();
        break;
    case R.id.menu_debug_notify:
        intentx = new Intent(ReminderAlarmService.ACTION_NOTIFY_DEBUG);
        intentx.setClass(this, ReminderAlarmService.class);
        this.startService(intentx);
        return true;
    case R.id.menu_debug_view_live_match:
        final Intent intent = new Intent(this, LiveGameStatsActivity.class);
        intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TLL, (String) null);
        intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TLR, (String) null);
        intent.putExtra(LiveGameStatsActivity.ARGS_GAME_BO, "best of 1");
        intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TNL, "Invasion");
        intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TNR, "Koopa");
        intent.putExtra(LiveGameStatsActivity.ARGS_GAME_TN, "awesome");

        final Context mContext = this;

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

        alert.setTitle("Enter Match Id:");

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

        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                intent.putExtra(LiveGameStatsActivity.ARGS_GAME_MID,
                        Long.parseLong(input.getText().toString()));
                mContext.startActivity(intent);
            }
        });

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

        alert.show();

        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.fastbootmobile.encore.app.fragments.NewPlaylistFragment.java

@NonNull
@Override/*w  w w.j a  v a2 s . com*/
public Dialog onCreateDialog(Bundle savedInstance) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View root = inflater.inflate(R.layout.dialog_new_playlist, null);
    final TextView playlistName = (TextView) root.findViewById(R.id.et_playlist_name);
    final CheckBox multiProviderPlaylist = (CheckBox) root.findViewById(R.id.cb_provider_specific);
    builder.setView(root).setPositiveButton(getString(R.string.create), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String playlistNameStr = playlistName.getText().toString().trim();
            if (!playlistNameStr.isEmpty()) {
                Log.d(TAG, "Adding new playlist named '" + playlistNameStr + "'");

                try {
                    ProviderConnection connection;
                    if (multiProviderPlaylist.isChecked()) {
                        connection = PluginsLookup.getDefault().getMultiProviderPlaylistProvider();
                    } else {
                        ProviderIdentifier identifier;
                        if (mSong != null) {
                            identifier = mSong.getProvider();
                        } else if (mAlbum != null) {
                            identifier = mAlbum.getProvider();
                        } else if (mPlaylist != null) {
                            identifier = mPlaylist.getProvider();
                        } else {
                            throw new IllegalStateException(
                                    "Song, Album and Playlist are all null, cannot determine provider!");
                        }

                        connection = PluginsLookup.getDefault().getProvider(identifier);
                    }

                    IMusicProvider binder = connection.getBinder();
                    String playlistRef = binder.addPlaylist(playlistName.getText().toString());

                    if (playlistRef != null) {
                        if (mSong != null) {
                            binder.addSongToPlaylist(mSong.getRef(), playlistRef, mSong.getProvider());
                        } else if (mAlbum != null) {
                            Iterator<String> songs = mAlbum.songs();
                            while (songs.hasNext()) {
                                binder.addSongToPlaylist(songs.next(), playlistRef, mAlbum.getProvider());
                            }
                        } else if (mPlaylist != null) {
                            Iterator<String> songs = mPlaylist.songs();
                            while (songs.hasNext()) {
                                // TODO: This might cause issues if we add a playlist
                                // from a multi-provider playlist to another one
                                binder.addSongToPlaylist(songs.next(), playlistRef, mPlaylist.getProvider());
                            }
                        }
                    } else {
                        throw new IllegalStateException("Playlist reference returned by the provider is null!");
                    }
                } catch (Exception e) {
                    Log.e(TAG, "Unable to add playlist", e);
                    Toast.makeText(getActivity(),
                            getString(R.string.toast_playlist_track_add_error, playlistNameStr),
                            Toast.LENGTH_SHORT).show();
                }

            } else {
                Utils.shortToast(getActivity(), R.string.enter_name);
            }
        }

    }).setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    }).setTitle(getString(R.string.new_playlist));
    return builder.create();

}

From source file:de.dmxcontrol.fragment.ActionSelectorFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d(TAG, "onCreateView");

    LinearLayout actionButtons = (LinearLayout) inflater.inflate(R.layout.action_selector_fragment, container,
            false);/*w  w w. j  ava 2s .  c o  m*/

    ViewGroup vg = (ViewGroup) actionButtons.findViewById(R.id.action_selector_scroll);
    scrollView = vg;

    bDeviceAction = (Button) actionButtons.findViewById(R.id.button_device_action);
    bDeviceAction.setOnClickListener(this);
    bDeviceAction.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            try {
                AlertDialog.Builder alert = new AlertDialog.Builder(v.getContext());
                alert.setTitle("Parameter");
                final DeviceManagerDialog view = new DeviceManagerDialog(alert.getContext());
                alert.setView(view);
                alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        try {
                            ServiceFrontend.get().sendMessage(view.GetDeviceMetadata().getBytes());
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
                AlertDialog alertDialog = alert.create();
                alertDialog.show();
                return true;
            } catch (Exception e) {
                return false;
            }
        }
    });

    bColorAction = (Button) actionButtons.findViewById(R.id.button_color_action);
    bColorAction.setOnClickListener(this);

    bIntensityAction = (Button) actionButtons.findViewById(R.id.button_intensity_action);
    bIntensityAction.setOnClickListener(this);

    bPanTiltAction = (Button) actionButtons.findViewById(R.id.button_pantilt_action);
    bPanTiltAction.setOnClickListener(this);

    bGoboAction = (Button) actionButtons.findViewById(R.id.button_gobo_action);
    bGoboAction.setOnClickListener(this);

    bOpticAction = (Button) actionButtons.findViewById(R.id.button_optic_action);
    bOpticAction.setOnClickListener(this);

    bPrismAction = (Button) actionButtons.findViewById(R.id.button_prism_action);
    bPrismAction.setOnClickListener(this);
    //bOpticAction.setVisibility(View.INVISIBLE);
    //actionButtons.removeView(bOpticAction);

    bRawAction = (Button) actionButtons.findViewById(R.id.button_raw_action);
    bRawAction.setOnClickListener(this);
    //bRawAction.setVisibility(View.INVISIBLE);
    //actionButtons.removeView(bRawAction);

    bEffectAction = (Button) actionButtons.findViewById(R.id.button_effect_action);
    bEffectAction.setOnClickListener(this);
    //bEffectAction.setVisibility(View.INVISIBLE);
    //actionButtons.removeView(bEffectAction);

    bPresetAction = (Button) actionButtons.findViewById(R.id.button_preset_action);
    bPresetAction.setOnClickListener(this);

    bProgrammerAction = (Button) actionButtons.findViewById(R.id.button_programmer_action);
    bProgrammerAction.setOnClickListener(this);

    updateStateSelected();
    return actionButtons;
}

From source file:com.androzic.route.RouteSave.java

@NonNull
@SuppressLint("InflateParams")
@Override/*w  ww  . j  av a  2  s  . co m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle(getString(R.string.saveroute_name));
    final View view = getActivity().getLayoutInflater().inflate(R.layout.act_save, null);

    filename = (TextView) view.findViewById(R.id.filename_text);

    if (route.filepath != null) {
        File file = new File(route.filepath);
        filename.setText(file.getName());
    } else {
        filename.setText(FileUtils.sanitizeFilename(route.name) + ".rt2");
    }

    builder.setView(view);
    builder.setPositiveButton(R.string.save, saveOnClickListener);
    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            getDialog().cancel();
        }
    });

    return builder.create();
}

From source file:com.cmput301w15t15.travelclaimsapp.activitys.EditClaimActivity.java

/**
 * Create a alert dialog for entering Destination values 
 * // w w  w.  j  a  v a 2s  .  co m
 */
private void showDestinationAlert(final String dlocation, final String dreason) {
    final EditText enterLocation = new EditText(this);
    final EditText enterReason = new EditText(this);

    if (!dlocation.equals("")) {
        enterLocation.setText(dlocation);
    }
    if (!dreason.equals("")) {
        enterReason.setText(dreason);
    }
    enterLocation.setHint("Enter location");
    enterReason.setHint("Enter reason");

    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(enterLocation);
    linearLayout.addView(enterReason);

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

    alert.setView(linearLayout);

    alert.setPositiveButton("Add", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            Destination dest = new Destination(enterLocation.getText().toString(),
                    enterReason.getText().toString());
            ClaimListController.addDestination(dest, theClaim);

            //open Map activity and make user pick a geolocation
            Intent intent = GeoLocationController.pickLocationIntent(EditClaimActivity.this);
            startActivityForResult(intent, GET_GEOLOCATION_CODE);

            destAdaptor.notifyDataSetChanged();

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

    alert.show();
}

From source file:com.miuidev.themebrowser.MainActivity.java

private void displayAbout() {
    AlertDialog.Builder builder;
    AlertDialog alertDialog;/* w w w.  ja  va  2s .c o m*/

    LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.dialog_about,
            (ViewGroup) findViewById(R.id.DialogAboutRelativeLayout));

    TextView text = (TextView) layout.findViewById(R.id.AboutVersionValue);
    text.setText(getVersionName());

    builder = new AlertDialog.Builder(this);
    builder.setView(layout);
    builder.setCancelable(false).setPositiveButton(getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.dismiss();
                }
            });
    alertDialog = builder.create();
    alertDialog.show();

}

From source file:it.scoppelletti.mobilepower.app.HelpDialogFragment.java

/**
 * Crea il dialogo./*from ww w.j  a  va2s . c o m*/
 * 
 * @param  savedInstanceState Stato dell&rsquo;istanza.
 * @return                    Dialogo.
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    int mode, resId;
    View contentView;
    AlertDialog dlg;
    AlertDialog.Builder builder;
    LayoutInflater inflater;
    TextView textControl;
    Bundle args = getArguments();

    builder = newAlertDialogBuilder();

    resId = args.getInt(HelpDialogFragment.ARG_TITLEID, 0);
    if (resId > 0) {
        builder.setTitle(resId);
    }

    inflater = getActivity().getLayoutInflater();
    contentView = inflater.inflate(R.layout.helpdialog, null);
    builder.setView(contentView);

    builder.setIcon(android.R.drawable.ic_dialog_info);

    mode = getArguments().getInt(HelpDialogFragment.ARG_MODE, HelpDialogFragment.MODE_HELP);
    switch (mode) {
    case HelpDialogFragment.MODE_CONFIRM:
        setCancelable(false);
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.cmd_proceed, this);
        builder.setNegativeButton(android.R.string.cancel, this);
        break;

    default: // HelpDialogFragment.MODE_HELP
        builder.setNeutralButton(R.string.cmd_close, null);
        break;
    }

    dlg = builder.create();

    textControl = (TextView) contentView.findViewById(R.id.txt_help);
    textControl.setKeyListener(null);

    resId = args.getInt(HelpDialogFragment.ARG_TEXTID, 0);
    if (resId > 0) {
        textControl.setText(Html.fromHtml(getResources().getString(resId)));
    }

    return dlg;
}