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:net.granoeste.scaffold.app.ScaffoldAlertDialogFragment.java

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    int iconId = getArguments().getInt(ICON_ID, 0);
    String title = getArguments().getString(TITLE);
    String message = getArguments().getString(MESSAGE);
    boolean hasPositive = getArguments().getBoolean(HAS_POSITIVE, false);
    boolean hasNeutral = getArguments().getBoolean(HAS_NEUTRAL, false);
    boolean hasNegative = getArguments().getBoolean(HAS_NEGATIVE, false);
    String positiveText = getArguments().getString(POSITIVE_TEXT);
    String neutralText = getArguments().getString(NEUTRAL_TEXT);
    String negativeText = getArguments().getString(NEGATIVE_TEXT);
    boolean cancelable = getArguments().getBoolean(CANCELABLE, true);
    boolean canceledOnTouchOutside = getArguments().getBoolean(CANCELED_ON_TOUCH_OUTSIDE, false);

    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    if (iconId > 0) {
        builder.setIcon(iconId);//from  w  ww . ja  v  a  2 s .  c om
    }
    if (StringUtils.isNoneEmpty(title)) {
        builder.setTitle(title);
    }
    if (StringUtils.isNoneEmpty(message)) {
        builder.setMessage(message);
    }
    if (hasPositive) {
        if (StringUtils.isEmpty(positiveText)) {
            positiveText = getResources().getString(R.string.yes);
        }
        builder.setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int whichButton) {
                synchronized (mOnAlertDialogEventListeners) {
                    for (OnAlertDialogEventListener listener : mOnAlertDialogEventListeners) {
                        listener.onDialogClick(dialog, whichButton, getTag());
                    }
                }
            }
        });
    }
    if (hasNeutral) {
        if (StringUtils.isEmpty(neutralText)) {
            neutralText = getResources().getString(R.string.no);
        }
        builder.setNeutralButton(neutralText, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int whichButton) {
                synchronized (mOnAlertDialogEventListeners) {
                    for (OnAlertDialogEventListener listener : mOnAlertDialogEventListeners) {
                        listener.onDialogClick(dialog, whichButton, getTag());
                    }
                }
            }
        });
    }
    if (hasNegative) {
        if (StringUtils.isEmpty(negativeText)) {
            negativeText = getResources().getString(hasNeutral ? R.string.cancel : R.string.no);
        }
        builder.setNegativeButton(negativeText, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int whichButton) {
                synchronized (mOnAlertDialogEventListeners) {
                    for (OnAlertDialogEventListener listener : mOnAlertDialogEventListeners) {
                        listener.onDialogClick(dialog, whichButton, getTag());
                    }
                }
            }
        });
    }
    builder.setCancelable(cancelable);
    if (cancelable) {
        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(final DialogInterface dialog) {
                synchronized (mOnAlertDialogEventListeners) {
                    for (OnAlertDialogEventListener listener : mOnAlertDialogEventListeners) {
                        listener.onDialogCancel(dialog, getTag());
                    }
                }
            }
        });
    }
    //        View customView = getCustomView();
    if (mCustomView != null) {
        builder.setView(mCustomView);
    }

    Dialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(canceledOnTouchOutside);

    return dialog;
}

From source file:com.dattasmoon.pebble.plugin.EditNotificationActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (Constants.IS_LOGGABLE) {
        Log.i(Constants.LOG_TAG, "Selected menu item id: " + String.valueOf(item.getItemId()));
    }//from w ww.  ja  v  a2s.  co m
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    View v;
    ListViewHolder viewHolder;
    AdapterView.AdapterContextMenuInfo contextInfo;
    String app_name;
    final String package_name;
    switch (item.getItemId()) {
    case R.id.btnUncheckAll:

        builder.setTitle(R.string.dialog_confirm_title);
        builder.setMessage(getString(R.string.dialog_uncheck_message));
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int buttonId) {
                if (lvPackages == null || lvPackages.getAdapter() == null
                        || ((packageAdapter) lvPackages.getAdapter()).selected == null) {
                    //something went wrong
                    return;
                }
                ((packageAdapter) lvPackages.getAdapter()).selected.clear();
                lvPackages.invalidateViews();
            }
        });
        builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int buttonId) {
                //do nothing!
            }
        });
        builder.setIcon(android.R.drawable.ic_dialog_alert);
        builder.show();

        return true;
    case R.id.btnSave:
        finish();
        return true;
    case R.id.btnDonate:
        Intent i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(Constants.DONATION_URL));
        startActivity(i);
        return true;
    case R.id.btnSettings:
        Intent settings = new Intent(this, SettingsActivity.class);
        startActivity(settings);
        return true;
    case R.id.btnRename:
        contextInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        int position = contextInfo.position;
        long id = contextInfo.id;
        // the child view who's info we're viewing (should be equal to v)
        v = contextInfo.targetView;
        app_name = ((TextView) v.findViewById(R.id.tvPackage)).getText().toString();
        viewHolder = (ListViewHolder) v.getTag();
        if (viewHolder == null || viewHolder.chkEnabled == null) {
            //failure
            return true;
        }
        package_name = (String) viewHolder.chkEnabled.getTag();
        builder.setTitle(R.string.dialog_title_rename_notification);
        final EditText input = new EditText(this);
        input.setHint(app_name);
        builder.setView(input);
        builder.setPositiveButton(R.string.confirm, null);
        builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //do nothing
            }
        });
        final AlertDialog d = builder.create();
        d.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                Button b = d.getButton(AlertDialog.BUTTON_POSITIVE);
                if (b != null) {
                    b.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            //can't be nothing
                            if (input.getText().length() > 0) {
                                if (Constants.IS_LOGGABLE) {
                                    Log.i(Constants.LOG_TAG,
                                            "Adding rename for " + package_name + " to " + input.getText());
                                }
                                JSONObject rename = new JSONObject();
                                try {
                                    rename.put("pkg", package_name);
                                    rename.put("to", input.getText());
                                    arrayRenames.put(rename);
                                } catch (JSONException e) {
                                    e.printStackTrace();
                                }
                                ((packageAdapter) lvPackages.getAdapter()).notifyDataSetChanged();

                                d.dismiss();
                            } else {
                                input.setText(R.string.error_cant_be_blank);
                            }

                        }
                    });
                }
            }
        });

        d.show();

        return true;
    case R.id.btnRemoveRename:
        contextInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
        // the child view who's info we're viewing (should be equal to v)
        v = contextInfo.targetView;
        app_name = ((TextView) v.findViewById(R.id.tvPackage)).getText().toString();
        viewHolder = (ListViewHolder) v.getTag();
        if (viewHolder == null || viewHolder.chkEnabled == null) {
            if (Constants.IS_LOGGABLE) {
                Log.i(Constants.LOG_TAG, "Viewholder is null or chkEnabled is null");
            }
            //failure
            return true;
        }
        package_name = (String) viewHolder.chkEnabled.getTag();
        builder.setTitle(
                getString(R.string.dialog_title_remove_rename) + app_name + " (" + package_name + ")?");
        builder.setPositiveButton(R.string.confirm, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG, "Before remove is: " + String.valueOf(arrayRenames.length()));
                }
                JSONArray tmp = new JSONArray();
                try {
                    for (int i = 0; i < arrayRenames.length(); i++) {
                        if (!arrayRenames.getJSONObject(i).getString("pkg").equalsIgnoreCase(package_name)) {
                            tmp.put(arrayRenames.getJSONObject(i));
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                arrayRenames = tmp;
                if (Constants.IS_LOGGABLE) {
                    Log.i(Constants.LOG_TAG, "After remove is: " + String.valueOf(arrayRenames.length()));
                }
                ((packageAdapter) lvPackages.getAdapter()).notifyDataSetChanged();
            }
        });
        builder.setNegativeButton(R.string.decline, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //do nothing
            }
        });
        builder.show();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.aujur.ebookreader.activity.ReadingFragment.java

private void showHighlightEditDialog(final HighLight highLight) {
    final AlertDialog.Builder editalert = new AlertDialog.Builder(context);

    editalert.setTitle(R.string.text_note);
    final EditText input = new EditText(context);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    input.setLayoutParams(lp);//from   w  w  w.  j a  v a  2  s .c o  m
    editalert.setView(input);
    input.setText(highLight.getTextNote());

    editalert.setPositiveButton(R.string.save_note, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            highLight.setTextNote(input.getText().toString());
            bookView.update();
            highlightManager.saveHighLights();
        }
    });
    editalert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {

        }
    });

    editalert.setNeutralButton(R.string.clear_note, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
            highLight.setTextNote(null);
            bookView.update();
            highlightManager.saveHighLights();
        }
    });

    editalert.show();
}

From source file:cl.gisred.android.LectorActivity.java

public void dialogBusqueda() {

    AlertDialog.Builder dialogBusqueda = new AlertDialog.Builder(this);
    dialogBusqueda.setTitle("Busqueda");
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View v = inflater.inflate(R.layout.dialog_busqueda, null);
    dialogBusqueda.setView(v);

    Spinner spinner = (Spinner) v.findViewById(R.id.spinnerBusqueda);
    final LinearLayout llBuscar = (LinearLayout) v.findViewById(R.id.llBuscar);
    final LinearLayout llDireccion = (LinearLayout) v.findViewById(R.id.llBuscarDir);

    ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(this,
            R.layout.support_simple_spinner_dropdown_item, searchArray);

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);//from  w w w  .  jav  a2 s .  c  o  m
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            SpiBusqueda = position;

            if (position != 4) {
                if (llDireccion != null)
                    llDireccion.setVisibility(View.GONE);
                if (llBuscar != null)
                    llBuscar.setVisibility(View.VISIBLE);
            } else {
                if (llDireccion != null)
                    llDireccion.setVisibility(View.VISIBLE);
                if (llBuscar != null)
                    llBuscar.setVisibility(View.GONE);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
            Toast.makeText(getApplicationContext(), "Nada seleccionado", Toast.LENGTH_SHORT).show();
        }
    });

    final EditText eSearch = (EditText) v.findViewById(R.id.txtBuscar);
    final EditText eStreet = (EditText) v.findViewById(R.id.txtCalle);
    final EditText eNumber = (EditText) v.findViewById(R.id.txtNum);

    dialogBusqueda.setPositiveButton("Buscar", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

            if (SpiBusqueda == 4) {
                txtBusqueda = new String();
                if (!eStreet.getText().toString().isEmpty())
                    txtBusqueda = (eNumber.getText().toString().trim().isEmpty()) ? "0 "
                            : eNumber.getText().toString().trim() + " ";
                txtBusqueda = txtBusqueda + eStreet.getText().toString();
            } else {
                if (SpiBusqueda > 1)
                    txtBusqueda = eSearch.getText().toString();
                else
                    txtBusqueda = Util.extraerNum(eSearch.getText().toString());
            }

            if (txtBusqueda.trim().isEmpty()) {
                Toast.makeText(myMapView.getContext(), "Debe ingresar un valor", Toast.LENGTH_SHORT).show();
            } else {
                // Escala de calle para busquedas por default

                iBusqScale = 4000;
                switch (SpiBusqueda) {
                case 0:
                    callQuery(txtBusqueda, getValueByEmp("CLIENTES_XY_006.nis"),
                            LyCLIENTES.getUrl().concat("/0"));
                    if (LyCLIENTES.getLayers() != null && LyCLIENTES.getLayers().length > 0)
                        iBusqScale = LyCLIENTES.getLayers()[0].getLayerServiceInfo().getMinScale();
                    break;
                case 1:
                    callQuery(txtBusqueda, "codigo", LySED.getUrl().concat("/1"));
                    if (LySED.getLayers() != null && LySED.getLayers().length > 1)
                        iBusqScale = LySED.getLayers()[1].getLayerServiceInfo().getMinScale();
                    break;
                case 2:
                    callQuery(txtBusqueda, "rotulo", LyPOSTES.getUrl().concat("/0"));
                    if (LyPOSTES.getLayers() != null && LyPOSTES.getLayers().length > 0)
                        iBusqScale = LyPOSTES.getLayers()[0].getLayerServiceInfo().getMinScale();
                    break;
                case 3:
                    callQuery(txtBusqueda, "serie_medidor", LyMEDIDORES.getUrl().concat("/1"));
                    if (LyMEDIDORES.getLayers() != null && LyMEDIDORES.getLayers().length > 1)
                        iBusqScale = LyMEDIDORES.getLayers()[1].getLayerServiceInfo().getMinScale();
                    break;
                case 4:
                    iBusqScale = 5000;
                    String[] sBuscar = { eStreet.getText().toString(), eNumber.getText().toString() };
                    String[] sFields = { "nombre_calle", "numero" };
                    callQuery(sBuscar, sFields, LyDIRECCIONES.getUrl().concat("/0"));
                    break;
                case 5:
                    callQuery(txtBusqueda, new String[] { "id_equipo", "nombre" },
                            LyEQUIPOSLINEA.getUrl().concat("/0"));
                    if (LyEQUIPOSLINEA.getLayers() != null && LyEQUIPOSLINEA.getLayers().length > 0)
                        iBusqScale = LyEQUIPOSLINEA.getLayers()[0].getLayerServiceInfo().getMinScale();
                    break;
                }
            }
        }
    });

    dialogBusqueda.setNegativeButton("Cancelar", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });

    dialogBusqueda.show();
}

From source file:com.citrus.sample.WalletPaymentFragment.java

private void showDynamicPricingPrompt() {
    final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
    String message = "Apply Dynamic Pricing";
    String positiveButtonText = "Apply";
    final Utils.DPRequestType[] dpRequestType = new Utils.DPRequestType[1];
    ScrollView scrollView = new ScrollView(getActivity());
    LinearLayout linearLayout = (LinearLayout) getActivity().getLayoutInflater()
            .inflate(R.layout.dynamic_pricing_input_layout, null);
    final EditText editTransactionAmount = (EditText) linearLayout.findViewById(R.id.edit_txn_amount);
    final EditText editCouponCode = (EditText) linearLayout.findViewById(R.id.edit_coupon_code);
    final EditText editAlteredAmount = (EditText) linearLayout.findViewById(R.id.edit_altered_amount);
    final LinearLayout layoutCouponCode = (LinearLayout) linearLayout.findViewById(R.id.layout_for_coupon_code);
    final LinearLayout layoutAlteredAmount = (LinearLayout) linearLayout
            .findViewById(R.id.layout_for_altered_amount);
    Spinner spinner = (Spinner) linearLayout.findViewById(R.id.spinner_dp_request_type);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override/*from  w ww  .  j  av  a2  s. c om*/
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {

            switch (position) {
            case 0:
                dpRequestType[0] = Utils.DPRequestType.SEARCH_AND_APPLY;
                layoutCouponCode.setVisibility(View.GONE);
                layoutAlteredAmount.setVisibility(View.GONE);
                break;
            case 1:
                dpRequestType[0] = Utils.DPRequestType.CALCULATE_PRICING;
                layoutCouponCode.setVisibility(View.VISIBLE);
                layoutAlteredAmount.setVisibility(View.GONE);
                break;
            case 2:
                dpRequestType[0] = Utils.DPRequestType.VALIDATE_RULE;
                layoutCouponCode.setVisibility(View.VISIBLE);
                layoutAlteredAmount.setVisibility(View.VISIBLE);
                break;
            }
        }

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

        }
    });

    alert.setTitle("Perform Dynamic Pricing");
    alert.setMessage(message);

    scrollView.addView(linearLayout);
    alert.setView(scrollView);
    alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            String amount = editTransactionAmount.getText().toString();
            String alteredAmount = editAlteredAmount.getText().toString();
            String couponCode = editCouponCode.getText().toString();

            mListener.onPaymentTypeSelected(dpRequestType[0], new Amount(amount), couponCode,
                    new Amount(alteredAmount));

            // Hide the keyboard.
            InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editTransactionAmount.getWindowToken(), 0);
        }
    });

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

    editTransactionAmount.requestFocus();
    alert.show();
}

From source file:com.Duo.music.player.SettingsActivity.SettingsMusicFoldersDialog.java

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

    mContext = getActivity().getApplicationContext();
    mApp = (Common) mContext;//from ww w . j a va 2 s .c  o  m
    View rootView = getActivity().getLayoutInflater().inflate(R.layout.fragment_folders_selection, null);
    mMusicFolders = new HashMap<String, Boolean>();

    mFoldersListView = (ListView) rootView.findViewById(R.id.folders_list_view);
    mFoldersListView.setFastScrollEnabled(true);
    mWelcomeSetup = getArguments().getBoolean("com.jams.music.player.WELCOME");

    mUpLayout = (RelativeLayout) rootView.findViewById(R.id.folders_up_layout);
    mUpIcon = (ImageView) rootView.findViewById(R.id.folders_up_icon);
    mUpText = (TextView) rootView.findViewById(R.id.folders_up_text);
    mCurrentFolderText = (TextView) rootView.findViewById(R.id.folders_current_directory_text);

    mUpText.setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Regular"));
    mCurrentFolderText.setTypeface(TypefaceHelper.getTypeface(mContext, "Roboto-Regular"));

    mUpLayout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                getDir(new File(mCurrentDir).getParentFile().getCanonicalPath());
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    });

    if (mWelcomeSetup) {
        mFoldersListView.setDivider(getResources().getDrawable(R.drawable.icon_list_divider_light));
        mUpIcon.setImageResource(R.drawable.up);
    } else {
        mUpIcon.setImageResource(UIElementsHelper.getIcon(mContext, "up"));

        if (mApp.getCurrentTheme() == Common.DARK_THEME) {
            mUpIcon.setImageResource(R.drawable.icon_list_divider_light);
        } else {
            mUpIcon.setImageResource(R.drawable.icon_list_divider);
        }

    }

    mFoldersListView.setDividerHeight(1);
    mRootDir = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
    mCurrentDir = mRootDir;

    //Get a mCursor with a list of all the current folder paths (will be empty if this is the first run).
    mCursor = mApp.getDBAccessHelper().getAllMusicFolderPaths();

    //Get a list of all the paths that are currently stored in the DB.
    for (int i = 0; i < mCursor.getCount(); i++) {
        mCursor.moveToPosition(i);

        //Filter out any double slashes.
        String path = mCursor.getString(mCursor.getColumnIndex(DBAccessHelper.FOLDER_PATH));
        if (path.contains("//")) {
            path.replace("//", "/");
        }

        mMusicFolders.put(path, true);
    }

    //Close the cursor.
    if (mCursor != null)
        mCursor.close();

    //Get the folder hierarchy of the selected folder.
    getDir(mRootDir);

    mFoldersListView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int index, long arg3) {
            String newPath = mFileFolderPathsList.get(index);
            getDir(newPath);

        }

    });

    builder.setTitle(R.string.select_music_folders);
    builder.setView(rootView);
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            getActivity().finish();

            Intent intent = new Intent(mContext, WelcomeActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
            intent.putExtra("REFRESH_MUSIC_LIBRARY", true);
            mContext.startActivity(intent);

        }

    });

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

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();

        }

    });

    return builder.create();
}

From source file:com.citrus.sample.WalletPaymentFragment.java

private void showCashoutPrompt() {
    final AlertDialog.Builder alert = new AlertDialog.Builder(getActivity());
    String message = "Please enter account details.";
    String positiveButtonText = "Withdraw";

    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    final TextView labelAmount = new TextView(getActivity());
    final EditText editAmount = new EditText(getActivity());
    final TextView labelAccountNo = new TextView(getActivity());
    final EditText editAccountNo = new EditText(getActivity());
    editAccountNo.setSingleLine(true);//from   w w w .  j  a  va  2s  .  c  om
    final TextView labelAccountHolderName = new TextView(getActivity());
    final EditText editAccountHolderName = new EditText(getActivity());
    editAccountHolderName.setSingleLine(true);
    final TextView labelIfscCode = new TextView(getActivity());
    final EditText editIfscCode = new EditText(getActivity());
    editIfscCode.setSingleLine(true);

    labelAmount.setText("Withdrawal Amount");
    labelAccountNo.setText("Account Number");
    labelAccountHolderName.setText("Account Holder Name");
    labelIfscCode.setText("IFSC Code");

    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

    labelAmount.setLayoutParams(layoutParams);
    labelAccountNo.setLayoutParams(layoutParams);
    labelAccountHolderName.setLayoutParams(layoutParams);
    labelIfscCode.setLayoutParams(layoutParams);
    editAmount.setLayoutParams(layoutParams);
    editAccountNo.setLayoutParams(layoutParams);
    editAccountHolderName.setLayoutParams(layoutParams);
    editIfscCode.setLayoutParams(layoutParams);

    linearLayout.addView(labelAmount);
    linearLayout.addView(editAmount);
    linearLayout.addView(labelAccountNo);
    linearLayout.addView(editAccountNo);
    linearLayout.addView(labelAccountHolderName);
    linearLayout.addView(editAccountHolderName);
    linearLayout.addView(labelIfscCode);
    linearLayout.addView(editIfscCode);

    int paddingPx = Utils.getSizeInPx(getActivity(), 32);
    linearLayout.setPadding(paddingPx, paddingPx, paddingPx, paddingPx);

    editAmount.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);

    alert.setTitle("Withdraw Money To Your Account");
    alert.setMessage(message);

    alert.setView(linearLayout);
    alert.setPositiveButton(positiveButtonText, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            String amount = editAmount.getText().toString();
            String accontNo = editAccountNo.getText().toString();
            String accountHolderName = editAccountHolderName.getText().toString();
            String ifsc = editIfscCode.getText().toString();

            CashoutInfo cashoutInfo = new CashoutInfo(new Amount(amount), accontNo, accountHolderName, ifsc);
            mListener.onCashoutSelected(cashoutInfo);

            // Hide the keyboard.
            InputMethodManager imm = (InputMethodManager) getActivity()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editAmount.getWindowToken(), 0);
        }
    });

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

    editAmount.requestFocus();
    alert.show();
}

From source file:com.example.android.lightcontrol.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.scan:
        // Launch the DeviceListActivity to see devices and do scan
        if (mChatService.getState() != BluetoothChatService.STATE_CONNECTED) {
            Intent serverIntent = new Intent(this, DeviceListActivity.class);
            startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE);
            return true;
        } else {/*from  w  w w  . java2 s  .  c  om*/
            Toast.makeText(MainActivity.this, "You have connected to a device", Toast.LENGTH_SHORT).show();
            return true;

        }
    case R.id.about:
        LayoutInflater inflater = LayoutInflater.from(this);
        final View v = inflater.inflate(R.layout.hello, null);
        final AlertDialog.Builder dialog = new AlertDialog.Builder(this);

        dialog.setCancelable(false);
        dialog.setTitle(R.string.about_title);
        dialog.setView(v);
        dialog.setPositiveButton(R.string.ok_label_1, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialoginterface, int i) {

            }
        });
        dialog.show();
        return true;
    case R.id.action_settings:
        if (!B) {
            // Launch the DeviceListActivity to see devices and do scan
            LayoutInflater inflater1 = LayoutInflater.from(this);
            final View v1 = inflater1.inflate(R.layout.login, null);
            final AlertDialog.Builder dialog1 = new AlertDialog.Builder(this);
            final EditText password = (EditText) v1.findViewById(R.id.editText2);

            dialog1.setCancelable(false);
            dialog1.setTitle("Enter the password");
            dialog1.setView(v1);
            dialog1.setPositiveButton(R.string.ok_label_1, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialoginterface, int i) {

                    if (password.getText().toString().equals(GlobalVariable.VAT_number)) {
                        fadetime();
                    } else {
                        Toast.makeText(MainActivity.this, "Error,wrong password!!", Toast.LENGTH_SHORT).show();
                    }

                }
            });
            dialog1.show();
            return true;
        } else {
            Toast.makeText(MainActivity.this, "Cannel round theme before set fadetime", Toast.LENGTH_SHORT)
                    .show();
        }
    case R.id.action_theme:
        LayoutInflater inflater1 = LayoutInflater.from(this);
        final View v2 = inflater1.inflate(R.layout.login, null);
        final AlertDialog.Builder dialog1 = new AlertDialog.Builder(this);
        final EditText password1 = (EditText) v2.findViewById(R.id.editText2);

        dialog1.setCancelable(false);
        dialog1.setTitle("Enter the password");
        dialog1.setView(v2);
        dialog1.setPositiveButton(R.string.ok_label_1, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialoginterface, int i) {

                if (password1.getText().toString().equals(GlobalVariable.VAT_number)) {
                    theme_to_who();
                } else {
                    Toast.makeText(MainActivity.this, "Error,wrong password!!", Toast.LENGTH_SHORT).show();
                }

            }
        });
        dialog1.show();
        return true;
    case R.id.action_light:
        LayoutInflater inflater2 = LayoutInflater.from(this);
        final View v3 = inflater2.inflate(R.layout.login, null);
        final AlertDialog.Builder dialog2 = new AlertDialog.Builder(this);
        final EditText password2 = (EditText) v3.findViewById(R.id.editText2);

        dialog2.setCancelable(false);
        dialog2.setTitle("Enter the password");
        dialog2.setView(v3);
        dialog2.setPositiveButton(R.string.ok_label_1, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialoginterface, int i) {

                if (password2.getText().toString().equals(GlobalVariable.VAT_number)) {
                    light_configure();
                } else {
                    Toast.makeText(MainActivity.this, "Error,wrong password!!", Toast.LENGTH_SHORT).show();
                }

            }
        });
        dialog2.show();
        return true;
    }
    return false;
}

From source file:com.aimfire.demo.CamcorderActivity.java

public void showHint3D() {
    if (checkShowHint(false/*is2d*/)) {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this,
                R.style.AppCompatAlertDialogStyle);
        alertDialogBuilder.setTitle(R.string.instruction);
        alertDialogBuilder.setView(R.layout.dialog_stacking);

        alertDialogBuilder.setPositiveButton(R.string.got_it, new DialogInterface.OnClickListener() {
            @Override// ww w .  j av a 2  s.  c  o  m
            public void onClick(DialogInterface arg0, int arg1) {
                //do nothing
            }
        });

        alertDialogBuilder.setNegativeButton(R.string.tutorial, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                mFirebaseAnalytics.logEvent(MainConsts.FIREBASE_CUSTOM_EVENT_ACTION_TUTORIAL, null);
                Intent intent = new Intent(Intent.ACTION_VIEW,
                        Uri.parse(getString(R.string.app_youtube_tutorial)));
                startActivity(intent);
            }
        });

        AlertDialog alertDialog = alertDialogBuilder.create();
        alertDialog.show();
    }

    int title;
    int text;
    if (mIsLeft) {
        title = R.string.leftCamHintTitle;
        text = R.string.leftCamHintText;
    } else {
        title = R.string.rightCamHintTitle;
        text = R.string.rightCamHintText;
    }

    final SimpleHintContentHolder camHintBlock = new SimpleHintContentHolder.Builder(getActivity())
            .setContentTitle(title).setContentText(text).setTitleStyle(R.style.HintTitleText)
            .setContentStyle(R.style.HintDescText).build();

    new HintCase(mParentView)
            .setHintBlock(camHintBlock, new FadeInContentHolderAnimator(), new FadeOutContentHolderAnimator())
            .show();
}