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.run_tracker.ProfileFragment.java

@Override
public void onClick(View arg0) {
    Log.v(TAG, "click");
    AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());

    alert.setTitle("Enter Password");
    alert.setMessage("Please enter your password");

    // Set an EditText view to get user input
    final EditText input = new EditText(getActivity());
    input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    alert.setView(input);

    alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            String password = input.getText().toString();
            String new_password = null;
            if (!mPassword1.getText().toString().equals(mPassword2.getText().toString())) {

                Toast.makeText(getActivity(), "Passwords dont match", Toast.LENGTH_LONG).show();
            } else {
                if (isEmpty(mPassword1) || (isEmpty(mPassword2))) {
                    new_password = password;
                } else {
                    new_password = mPassword1.getText().toString();
                }//from w ww  .j a  v  a2 s.  c  om
                Make_edit_profile_request(password, new_password);
            }

        }
    });

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

    alert.show();

}

From source file:edu.illinois.whereru.MainPageActivity.java

private void showRegistrationDialog() {

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    LayoutInflater factory = LayoutInflater.from(this);
    // inflate dialog view
    View view = factory.inflate(R.layout.dialog_user_registration, null);
    // Setting dialog message and title
    builder.setMessage(R.string.register_dialog_message).setTitle(R.string.register_dialog_title);
    // set custom view
    builder.setView(view);

    // need to get the edittext from dialog layout
    // calling findViewById automatically searches the layout attached to this activity
    editText = (EditText) view.findViewById(R.id.dialog_username_text);
    preferenceEditor = userInfo.edit();/*from   w  ww  . j  ava 2  s . c o m*/

    builder.setPositiveButton(R.string.register_button_text, new OnClickListener() {

        public void onClick(DialogInterface dialogs, int id) {
            String userName = editText.getText().toString();
            // TODO need to figure out a way to define a user with unique id
            String deviceID = Secure.getString(getContentResolver(), Secure.ANDROID_ID);

            // Connect to DB and store a new user
            DBConnector dbConnector = new DBConnector();
            dbConnector.execute(DBConnector.ADD_USER, userName, deviceID);
            JSONObject result = null;

            // Wait for the feedback from the DB
            try {
                result = dbConnector.get();
            } catch (InterruptedException e) {
                // shouldn't be interrupted
                Log.e(DEBUG_TAG, "Interrupted, restarting");
            } catch (ExecutionException e) {
                e.printStackTrace();
            }

            boolean successful = false;
            String userId = null;

            // Parse the response returned from DB
            if (result != null) {
                successful = JSONObjectParser.getSuccess(result);
                userId = JSONObjectParser.getUserId(result) + "";
            }

            if (successful) { // Store user info locally
                // user id returned from DB
                preferenceEditor.putString(PREF_USER_ID, userId);
                preferenceEditor.putString(PREF_USER_NAME, userName);
                preferenceEditor.putString(PREF_DEVICE_ID, deviceID);
                preferenceEditor.putBoolean(PREF_APPLICATION_STATE, false);
                preferenceEditor.commit();
                // start main tab activity
                startActivity(intent);
                finish();
            } else {
                // notify users of failure, let users press back button to exit.
                Toast.makeText(getApplicationContext(), "Failed to register, please try again later",
                        Toast.LENGTH_SHORT).show();
            }
        }

    });

    builder.setNegativeButton(R.string.register_dialog_cancel, new OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
            // exit out of this activity
            finish();
        }

    });

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

From source file:android.support.v7.preference.PreferenceDialogFragmentCompat.java

@Override
public @NonNull Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getActivity();
    mWhichButtonClicked = DialogInterface.BUTTON_NEGATIVE;

    final AlertDialog.Builder builder = new AlertDialog.Builder(context).setTitle(mDialogTitle)
            .setIcon(mDialogIcon).setPositiveButton(mPositiveButtonText, this)
            .setNegativeButton(mNegativeButtonText, this);

    View contentView = onCreateDialogView(context);
    if (contentView != null) {
        onBindDialogView(contentView);/*from   w  w w . ja v a 2  s  .  c  o  m*/
        builder.setView(contentView);
    } else {
        builder.setMessage(mDialogMessage);
    }

    onPrepareDialogBuilder(builder);

    // Create the dialog
    final Dialog dialog = builder.create();
    if (needInputMethod()) {
        requestInputMethod(dialog);
    }

    return dialog;
}

From source file:com.alivenet.dmvtaxi.fragment.FragmentRateYourRide.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.trip_completed, container, false);

    ratingBar = (RatingBar) view.findViewById(R.id.ratingbar);
    Text_tripcomplete_pickuplocation = (TextView) view.findViewById(R.id.tripcomplete_pickuplocation);
    Text_tripcomplete_dropoff_location = (TextView) view.findViewById(R.id.tripcomplete_dropoff_location);
    mname = (TextView) view.findViewById(R.id.tv_name);
    Text_tripcharged = (TextView) view.findViewById(R.id.tripcharged);
    mlicenceplate = (TextView) view.findViewById(R.id.tv_licenceplate);
    mtaname = (TextView) view.findViewById(R.id.tv_taname);
    mcommentbox = (EditText) view.findViewById(R.id.et_commentbox);
    btntip = (Button) view.findViewById(R.id.btntip);
    btnsubmit = (Button) view.findViewById(R.id.btnsubmit);
    icon = (ImageView) view.findViewById(R.id.tripcompltd_icons);

    mPref = getActivity().getSharedPreferences(MYPREF, Context.MODE_PRIVATE);
    mUserId = mPref.getString("userId", null);
    prgDialog = new ProgressDialog(getActivity());
    prgDialog.setMessage("Please wait...");
    prgDialog.setCancelable(false);/*ww w  .ja v  a  2 s  .c o  m*/
    btntip.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (MyApplication.RateyourRide == false) {

                LayoutInflater li = LayoutInflater.from(getContext());
                View promptsView = li.inflate(R.layout.prompts, null);

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
                alertDialogBuilder.setView(promptsView);
                tipValue = (EditText) promptsView.findViewById(R.id.edittip_value);
                // set dialog message
                alertDialogBuilder.setCancelable(false)
                        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                // get user input and set it to result
                                // edit text
                                if (tipValue.getText().toString().trim().length() == 0) {

                                } else {
                                    btntip.setText(String.format("Tip: $ %.2f",
                                            Double.valueOf(tipValue.getText().toString())));

                                }
                            }
                        }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });
                // create alert dialog
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();

                getToken(mUserId);

            }

        }
    });
    rideDriverComplete = sharedPreference.getDriverRidercompleate(getActivity());
    String rideId = MyApplication.RideId;
    if (rideDriverComplete == null && rideId != null) {

        ValidateRidecomplet(mUserId, rideId);
    }

    if (MyApplication.RateyourRide == true) {
        btnsubmit.setVisibility(View.GONE);
        mcommentbox.setVisibility(View.GONE);
    }

    if (rideDriverComplete != null) {

        if (rideDriverComplete.getPickupaddress() != null && rideDriverComplete.getPickupaddress() != " "
                && rideDriverComplete.getDestinationaddress() != null
                && rideDriverComplete.getDestinationaddress() != " ") {
            Text_tripcomplete_pickuplocation.setText(rideDriverComplete.getPickupaddress());
            Text_tripcomplete_dropoff_location.setText(rideDriverComplete.getDestinationaddress());
        }
        try {

            Picasso.with(getActivity()).load(MyPreferences.getActiveInstance(getActivity()).getImageUrl())
                    .error(R.mipmap.avtar).placeholder(R.mipmap.avtar).into(icon);
        } catch (Exception e) {
            e.printStackTrace();
        }

        mname.setText(rideDriverComplete.driverNameride);
        mlicenceplate.setText(rideDriverComplete.licenseId);
        mtaname.setText(rideDriverComplete.vehicle);
        Text_tripcharged
                .setText("$" + rideDriverComplete.getTotalfare() + "  HAS BEEN CHARGED TO YOUR CREDIT CARD");

        btnsubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String totalStars = "Total Stars:: " + ratingBar.getNumStars();
                String rating = "Rating :: " + ratingBar.getRating();
                String tip = "";
                if (rideDriverComplete != null) {

                    String driverid = rideDriverComplete.getDriverIdride();
                    String rideId = rideDriverComplete.getRideId();
                    if (tipValue != null)
                        tip = tipValue.getText().toString();

                    String comment = mcommentbox.getText().toString();
                    if (driverid != null && rideId != null && totalStars != null && tip != null) {

                        validateRideRating(mUserId, driverid, rideId, totalStars, tip, comment);
                    }

                }
            }
        });
    }

    view.setFocusableInTouchMode(true);
    view.requestFocus();
    view.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
                // handle back button's click listener

                if (keyCode == KeyEvent.KEYCODE_BACK) {

                    Fragment homeFragment = new FragmentMainScreen();
                    FragmentManager frgManager;
                    frgManager = getFragmentManager();
                    frgManager.beginTransaction().replace(R.id.fragment_switch, homeFragment).commit();

                    return true;
                }

                return true;
            }
            return false;
        }
    });

    return view;

}

From source file:app.wz.MainActivity.java

public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.menu_run_pause) {
        if (neuro.halt) {
            neuro.halt = false;/*from w  ww.ja v  a 2 s  . com*/
            setProgressBarIndeterminateVisibility(true);

            wakeLock.acquire();

            if (prefs.getBoolean("use_server", false))
                lock.acquire();

            // for the system's orientation sensor registered listeners
            mSensorManager.registerListener(this, mSensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
                    SensorManager.SENSOR_DELAY_GAME);

            synchronized (neuro) {
                neuro.notify();
            }
        } else {

            haltNeuro();
        }
    } else {
        if (!neuro.halt) {
            haltNeuro();
        }
    }

    if (id == R.id.menu_device_connect) {
        bt.setDeviceTarget(BluetoothState.DEVICE_OTHER);
        /*
        if(bt.getServiceState() == BluetoothState.STATE_CONNECTED)
         bt.disconnect();*/
        Intent intent = new Intent(getApplicationContext(), DeviceList.class);
        startActivityForResult(intent, BluetoothState.REQUEST_CONNECT_DEVICE);
    } else if (id == R.id.reset_Neuro) {
        neuro.updatePrefs(true);
        textRead.append("Reset Neuro \n");
        textScroll.fullScroll(View.FOCUS_DOWN);
    } else if (id == R.id.menu_disconnect) {
        if (bt.getServiceState() == BluetoothState.STATE_CONNECTED)
            bt.disconnect();
    } else if (id == R.id.remote_control) {
        if (bt.getServiceState() == BluetoothState.STATE_CONNECTED) {
            Intent intent = new Intent(this, JoystickActivity.class);
            startActivity(intent);
        } else {
            Toast.makeText(getApplicationContext(), "Not Connected", Toast.LENGTH_SHORT).show();
        }
        return true;
    } else if (id == R.id.action_settings) {
        Intent intent = new Intent(this, SettingsActivity.class);
        startActivity(intent);
        return true;
    } else if (id == R.id.help) {
        LayoutInflater li = LayoutInflater.from(this);
        View view = li.inflate(R.layout.help, null);
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setView(view);
        alert.show();
    }
    return super.onOptionsItemSelected(item);
}

From source file:adventure_fragments.Biking.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  www  . j a v a 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.addItemBiking(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsBiking();
                adapt = new CustomAdapter(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_bike);
                listItem.setAdapter(adapt);
                nothingtext = (TextView) rootView.findViewById(R.id.nothing_here_bike);
                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:com.example.sujit.myapplication.Get_Taxi.java

private void showProfile() {
    LayoutInflater li = LayoutInflater.from(this);
    //Creating a view to get the dialog box
    View confirmDialog = li.inflate(R.layout.dialog_profile, null);
    buttonCall = (AppCompatButton) confirmDialog.findViewById(R.id.buttonCall);
    textViewName1 = (TextView) confirmDialog.findViewById(R.id.textViewName1);
    textViewLicenseNo1 = (TextView) confirmDialog.findViewById(R.id.textViewLicenseNo1);
    textViewAddress1 = (TextView) confirmDialog.findViewById(R.id.textViewAddress1);
    textViewMobile1 = (TextView) confirmDialog.findViewById(R.id.textViewMobile1);
    textViewTaxiNo1 = (TextView) confirmDialog.findViewById(R.id.textViewTaxiNo1);

    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

    RequestQueue requestQueue = Volley.newRequestQueue(Get_Taxi.this);
    final ProgressDialog loading = ProgressDialog.show(this, "Getting Route", "Please wait...", false, false);

    StringRequest stringRequest = new StringRequest(Request.Method.POST, "", new Response.Listener<String>() {
        @Override/*www. j  a v a 2s  .c  o  m*/
        public void onResponse(String response) {
            loading.dismiss();
            try {
                JSONObject jsonObject = new JSONObject(response);
                JSONArray jsonArray = jsonObject.getJSONArray("drivers");
                JSONObject jsonObject1 = jsonArray.getJSONObject(0);

                textViewName1.setText(jsonObject1.getString("full_name"));
                textViewLicenseNo1.setText(jsonObject1.getString("license_number"));
                textViewAddress1.setText(jsonObject1.getString("address"));
                textViewMobile1.setText(jsonObject1.getString("mobile_number"));
                textViewTaxiNo1.setText(jsonObject1.getString("taxi_number"));
                alertDialog.show();

            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            loading.dismiss();
        }
    }) {
        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<>();
            params.put("latitude", String.valueOf(currentLatitude));
            params.put("longitude", String.valueOf(currentLongitude));

            return params;

        }

    };
    requestQueue.add(stringRequest);
    buttonCall.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            alertDialog.dismiss();
        }
    });
}

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

private Dialog removeDialog(Context context) {

    LayoutInflater inflater = LayoutInflater.from(context);
    final View textEntryView = inflater.inflate(R.layout.remove_id, null);
    final CheckBox rm_check = (CheckBox) textEntryView.findViewById(R.id.rm_local);
    rm_check.setText(R.string.remove_local);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setView(textEntryView);
    builder.setCancelable(false);/*from   ww  w  .j  a  v  a2s.c  o  m*/
    builder.setTitle(R.string.assign_remove_title);
    builder.setMessage(R.string.remove_msg);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub  

            cleanUp(ctx);//replace following

            //                    editor.putString(Utilities.SP_KEY_LOGIN_USERID, "");                       
            //                 editor.putString(Utilities.SP_KEY_LOGIN_USERPWD, "");
            //                 editor.putString(Utilities.SP_KEY_LOGIN_STUDY_STARTTIME, "");
            //                 editor.commit();

            // remove local file, if checked
            Log.d(TAG, "is checked " + rm_check.isChecked());
            if (rm_check.isChecked()) {
                deleteDirectory(Utilities.PHONE_BASE_PATH);
            }

            setHints();
            finish();
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub  

        }
    });

    return builder.create();

}

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

private Dialog removeDialog(Context context) {

    LayoutInflater inflater = LayoutInflater.from(context);
    final View textEntryView = inflater.inflate(R.layout.remove_id, null);
    final CheckBox rm_check = (CheckBox) textEntryView.findViewById(R.id.rm_local);
    rm_check.setText(R.string.remove_local);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setView(textEntryView);
    builder.setCancelable(false);/*from  www  .  j a v  a2  s. c  o  m*/
    builder.setTitle(R.string.assign_remove_title);
    builder.setMessage(R.string.remove_msg);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub

            cleanUp(ctx);

            cancelAlarms(ctx);

            // remove local file, if checked
            Log.d(TAG, "is checked " + rm_check.isChecked());
            if (rm_check.isChecked()) {
                deleteDirectory(Util.PHONE_BASE_PATH);
            }

            setHints();
            finish();
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub

        }
    });

    return builder.create();

}

From source file:adventure_fragments.Camping.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  www  . ja v  a 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.addItemCamping(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsCamping();
                adapt = new CustomAdapter1(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_camp);
                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.getAllItemsCamping();
            adapt = new CustomAdapter1(getActivity(), R.layout.item_layout, list);
            listItem = (ListView) getActivity().findViewById(R.id.listview_camp);
            listItem.setAdapter(adapt);

            dialog.dismiss();
        }
    });

    builder.show();
}