Example usage for android.app Dialog findViewById

List of usage examples for android.app Dialog findViewById

Introduction

In this page you can find the example usage for android.app Dialog findViewById.

Prototype

@Nullable
public <T extends View> T findViewById(@IdRes int id) 

Source Link

Document

Finds the first descendant view with the given ID or null if the ID is invalid (< 0), there is no matching view in the hierarchy, or the dialog has not yet been fully created (for example, via #show() or #create() ).

Usage

From source file:com.slownet5.pgprootexplorer.filemanager.ui.FileManagerActivity.java

private void showBackupDialog() {
    final Dialog dialog = new Dialog(this);
    dialog.setContentView(R.layout.password_dialog_layout);
    Button button = (Button) dialog.findViewById(R.id.decrypt_file_button);
    button.setText("Backup");
    ((TextInputLayout) dialog.findViewById(R.id.key_password_layout)).setHint("Application password");
    button.setOnClickListener(new View.OnClickListener() {
        @Override// w  w w . j a v a 2 s. c  o m
        public void onClick(View view) {
            String pass = ((EditText) dialog.findViewById(R.id.key_password)).getText().toString();
            if (pass.length() < 1) {
                Toast.makeText(FileManagerActivity.this, "Please input application password", Toast.LENGTH_LONG)
                        .show();
                return;
            }
            new BackupKeysTask().execute(pass);
            dialog.dismiss();
        }
    });
    dialog.findViewById(R.id.cancel_decrypt_button).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.dismiss();
        }
    });
    dialog.show();

}

From source file:com.slownet5.pgprootexplorer.filemanager.ui.FileManagerActivity.java

@ActionHandler(layoutResource = R.id.fab_add_folder)
public void onAddFloatingClicked(View v) {
    UiUtils.actionMode = this.actionMode;
    mFloatingActionsMenu.collapse();/* w ww  . j  a  v  a 2  s. co  m*/
    if (mCurrentFragment == null) {
        Log.d(TAG, "onAddFloatingClicked: fragment is null ");
        mCurrentFragment = mFragmentOnes[0];
    }
    if (isEmptyFolder) {
        removeNoFilesFragment();
    }
    final Dialog dialog = UiUtils.createDialog(this, "Create Folder", "create");

    final EditText folderEditText = (EditText) dialog.findViewById(R.id.foldername_edittext);
    Button okayButton = (Button) dialog.findViewById(R.id.create_file_button);

    okayButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String folderName = folderEditText.getText().toString();
            if (folderName.length() < 1) {
                folderEditText.setError("Give me the folder name");
            } else if (RootUtils.isRootPath(mCurrentFragment.getmCurrentPath())) {
                RootUtils.createFolder(mCurrentFragment.getmCurrentPath() + folderName);
                dialog.dismiss();
                UiUtils.reloadData(mCurrentFragment.getmFileAdapter());

            } else if (!FileUtils.createFolder(mCurrentFragment.getmCurrentPath() + folderName)) {
                Toast.makeText(FileManagerActivity.this,
                        "Cannot create folder make sure current path is writable", Toast.LENGTH_SHORT).show();
            } else {
                dialog.dismiss();
                //getContentResolver().insert(FileUtils.getUri(mCurrentFragment.getmCurrentPath()+folderName),null);
                //FileUtils.notifyChange(TextEditorActivity.this,mFile.getParent());
                FileUtils.notifyChange(FileManagerActivity.this,
                        mCurrentFragment.getmCurrentPath() + folderName);
                UiUtils.reloadData(mCurrentFragment.getmFileAdapter());
            }
        }
    });
}

From source file:net.evendanan.android.hagarfingerpainting.HagarFingerpaintingActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_NEW_PAPER:
        final Dialog newPaper = new Dialog(this);
        newPaper.setTitle(R.string.new_paper_dialog_title);
        newPaper.setContentView(R.layout.new_paper_dialog);
        newPaper.setCancelable(true);/*from   w ww .  j a v a 2  s .c o  m*/
        final EditText painterName = (EditText) newPaper.findViewById(R.id.painter_name_input_text);
        Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/schoolbell.ttf");
        painterName.setTypeface(tf);

        final Gallery colors = (Gallery) newPaper.findViewById(R.id.colors_list);
        colors.setAdapter(new PaperColorListAdapter(getApplicationContext()));
        colors.setOnItemSelectedListener(new OnItemSelectedListener() {
            private View mSelectedItem = null;

            @Override
            public void onItemSelected(AdapterView<?> adapter, View v, int position, long id) {
                if (mSelectedItem != null)
                    mSelectedItem.setBackgroundDrawable(null);

                mSelectedItem = v;
                if (mSelectedItem != null)
                    mSelectedItem.setBackgroundResource(R.drawable.selected_color_background);
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                if (mSelectedItem != null)
                    mSelectedItem.setBackgroundDrawable(null);
            }
        });

        colors.setSelection(2);

        View createButton = newPaper.findViewById(R.id.new_paper_create_button);
        createButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
                Editor e = sp.edit();

                final CharSequence painterNameFromUI = painterName.getText().toString();
                final String newPainterName = TextUtils.isEmpty(painterNameFromUI)
                        ? getString(R.string.settings_key_painter_name_default_value)
                        : painterNameFromUI.toString();
                e.putString(getString(R.string.settings_key_painter_name), newPainterName);

                e.commit();

                PaperBackground paper = (PaperBackground) colors.getSelectedItem();

                newPaper.dismiss();

                createNewPaper(paper);
            }
        });
        View cancelButton = newPaper.findViewById(R.id.new_paper_cancel_button);
        cancelButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                newPaper.dismiss();
                if (!mPaperCreated)
                    HagarFingerpaintingActivity.this.finish();
            }
        });
        newPaper.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                if (!mPaperCreated)
                    HagarFingerpaintingActivity.this.finish();
            }
        });

        return newPaper;
    default:
        return super.onCreateDialog(id);
    }
}

From source file:com.vkassin.mtrade.Common.java

public static void putArcDeal(final Context ctx) {

    final Dialog dialog = new Dialog(ctx);
    dialog.setContentView(R.layout.arcdeal_dialog);
    dialog.setTitle(R.string.ArcDealDialogTitle);

    datetxt = (EditText) dialog.findViewById(R.id.expdateedit);
    SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
    Date dat1 = new Date();
    datetxt.setText(sdf.format(dat1));/*from  w w w  .  j a  v a  2  s  . co m*/
    mYear = dat1.getYear() + 1900;
    mMonth = dat1.getMonth();
    mDay = dat1.getDate();
    final Date dat = new GregorianCalendar(mYear, mMonth, mDay).getTime();

    datetxt.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Log.i(TAG, "Show DatePickerDialog");
            DatePickerDialog dpd = new DatePickerDialog(ctx, mDateSetListener, mYear, mMonth, mDay);
            dpd.show();
        }
    });

    TextView itext = (TextView) dialog.findViewById(R.id.instrtext);
    itext.setText(Common.arcfilter);

    Button customDialog_Cancel = (Button) dialog.findViewById(R.id.cancelbutt);
    customDialog_Cancel.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            dialog.dismiss();
        }

    });

    Button customDialog_Put = (Button) dialog.findViewById(R.id.putorder);
    customDialog_Put.setOnClickListener(new Button.OnClickListener() {
        public void onClick(View arg0) {

            Double price = new Double(0);
            Long qval = new Long(0);
            final EditText pricetxt = (EditText) dialog.findViewById(R.id.priceedit);
            final EditText quanttxt = (EditText) dialog.findViewById(R.id.quantedit);

            try {

                price = Double.valueOf(pricetxt.getText().toString());
            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectPrice, Toast.LENGTH_SHORT).show();
                return;
            }
            try {

                qval = Long.valueOf(quanttxt.getText().toString());
            } catch (Exception e) {

                Toast.makeText(ctx, R.string.CorrectQty, Toast.LENGTH_SHORT).show();
                return;
            }

            //            if (dat.compareTo(new GregorianCalendar(mYear, mMonth, mDay)
            //            .getTime()) > 0) {
            //
            //               Toast.makeText(ctx, R.string.CorrectDate,
            //               Toast.LENGTH_SHORT).show();
            //
            //            return;
            //            }

            long maxkey = 0;
            Iterator<String> itr2 = arcdealMap.keySet().iterator();
            while (itr2.hasNext()) {
                String key1 = itr2.next();
                long k = Long.parseLong(key1);
                if (k > maxkey)
                    maxkey = k;
            }

            Deal adeal = new Deal();
            Iterator<String> itr1 = instrMap.keySet().iterator();
            while (itr1.hasNext()) {
                String key1 = itr1.next();
                Instrument in = instrMap.get(key1);
                if (in.symbol.equals(Common.arcfilter)) {

                    adeal.instrId = Long.valueOf(in.id);
                    break;
                }
            }

            final RadioButton bu0 = (RadioButton) dialog.findViewById(R.id.radio0);

            adeal.price = price;
            adeal.qty = qval;
            adeal.dtime = new GregorianCalendar(mYear, mMonth, mDay).getTimeInMillis();
            adeal.direct = bu0.isChecked() ? Long.valueOf(0) : Long.valueOf(1);
            Collection<String> lacc = Common.getAccountList();
            adeal.account = (lacc == null) ? "" : lacc.iterator().next();
            arcdealMap.put(String.valueOf(maxkey + 1), adeal);
            Common.saveArcDeals();
            Common.arcActivity.refresh();
            dialog.dismiss();
        }
    });

    dialog.show();

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = WindowManager.LayoutParams.FILL_PARENT;
    lp.height = WindowManager.LayoutParams.FILL_PARENT;
    dialog.getWindow().setAttributes(lp);

}

From source file:com.cettco.buycar.activity.OrderDetailActivity.java

private void initDialog() {
    final Dialog dialog = new Dialog(OrderDetailActivity.this);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(R.layout.popup_accept);
    dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
    dialog.show();/*from   ww  w  .  ja  v  a  2  s . co m*/
    Button cancelBtn = (Button) dialog.findViewById(R.id.popup_accept_cancel_btn);
    cancelBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    });
    Button payBtn = (Button) dialog.findViewById(R.id.popup_accept_pay_btn);
    payBtn.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

        }
    });
}

From source file:com.entertailion.android.launcher.Dialogs.java

/**
 * Display dialog to allow user to select which row to add the shortcut. For
 * TV channels let the user change the channel name.
 * /* w  ww. ja  v  a  2 s  .c o m*/
 * @see InstallShortcutReceiver
 * 
 * @param context
 * @param name
 * @param icon
 * @param uri
 */
public static void displayShortcutsRowSelection(final Launcher context, final String name, final String icon,
        final String uri) {
    if (uri == null) {
        return;
    }
    final Dialog dialog = new Dialog(context);
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    final boolean isChannel = uri.startsWith("tv");
    dialog.setContentView(R.layout.select_row);

    final TextView channelTextView = (TextView) dialog.findViewById(R.id.channelText);
    final EditText channelNameEditText = (EditText) dialog.findViewById(R.id.channelName);
    if (isChannel) {
        channelTextView.setVisibility(View.VISIBLE);
        channelNameEditText.setVisibility(View.VISIBLE);
        channelNameEditText.setText(name);
    }

    final TextView selectTextView = (TextView) dialog.findViewById(R.id.selectText);
    selectTextView.setText(context.getString(R.string.dialog_select_row, name));

    final Spinner spinner = (Spinner) dialog.findViewById(R.id.spinner);

    final EditText nameEditText = (EditText) dialog.findViewById(R.id.rowName);
    final RadioButton currentRadioButton = (RadioButton) dialog.findViewById(R.id.currentRadio);
    currentRadioButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // hide the row name edit field if the current row radio button
            // is selected
            nameEditText.setVisibility(View.GONE);
            spinner.setVisibility(View.VISIBLE);
        }

    });
    final RadioButton newRadioButton = (RadioButton) dialog.findViewById(R.id.newRadio);
    newRadioButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // show the row name edit field if the new radio button is
            // selected
            nameEditText.setVisibility(View.VISIBLE);
            nameEditText.requestFocus();
            spinner.setVisibility(View.GONE);
        }

    });

    List<String> list = new ArrayList<String>();
    final ArrayList<RowInfo> rows = RowsTable.getRows(context);
    if (rows != null) {
        for (RowInfo row : rows) {
            list.add(row.getTitle());
        }
    }
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(context, R.layout.simple_spinner_item, list);
    dataAdapter.setDropDownViewResource(R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(dataAdapter);

    Button buttonYes = (Button) dialog.findViewById(R.id.buttonOk);
    buttonYes.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            String shortcutName = name;
            try {
                if (isChannel) {
                    String channelName = channelNameEditText.getText().toString().trim();
                    if (channelName.length() == 0) {
                        channelNameEditText.requestFocus();
                        displayAlert(context, context.getString(R.string.dialog_channel_name_alert));
                        return;
                    }
                    shortcutName = channelName;
                }
                // if the new row radio button is selected, the user must
                // enter a name for the new row
                String rowName = nameEditText.getText().toString().trim();
                if (newRadioButton.isChecked() && rowName.length() == 0) {
                    nameEditText.requestFocus();
                    displayAlert(context, context.getString(R.string.dialog_new_row_name_alert));
                    return;
                }
                boolean currentRow = !newRadioButton.isChecked();
                int rowId = 0;
                int rowPosition = 0;
                if (currentRow) {
                    if (rows != null) {
                        String selectedRow = (String) spinner.getSelectedItem();
                        for (RowInfo row : rows) {
                            if (row.getTitle().equals(selectedRow)) {
                                rowId = row.getId();
                                ArrayList<ItemInfo> items = ItemsTable.getItems(context, rowId);
                                rowPosition = items.size(); // in last
                                // position
                                // for selected
                                // row
                                break;
                            }
                        }
                    }
                } else {
                    rowId = (int) RowsTable.insertRow(context, rowName, 0, RowInfo.FAVORITE_TYPE);
                    rowPosition = 0;
                }

                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(uri));
                ItemsTable.insertItem(context, rowId, rowPosition, shortcutName, intent, icon,
                        DatabaseHelper.SHORTCUT_TYPE);
                Toast.makeText(context, context.getString(R.string.shortcut_installed, shortcutName),
                        Toast.LENGTH_SHORT).show();
                context.reloadAllGalleries();

                if (currentRow) {
                    Analytics.logEvent(Analytics.ADD_SHORTCUT);
                } else {
                    Analytics.logEvent(Analytics.ADD_SHORTCUT_WITH_ROW);
                }

            } catch (Exception e) {
                Log.d(LOG_TAG, "onClick", e);
            }

            context.showCover(false);
            dialog.dismiss();
        }

    });
    Button buttonNo = (Button) dialog.findViewById(R.id.buttonCancel);
    buttonNo.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            context.showCover(false);
            dialog.dismiss();
        }

    });
    dialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            context.showCover(false);
        }

    });
    context.showCover(true);
    dialog.show();
    Analytics.logEvent(Analytics.DIALOG_ADD_SHORTCUT);
}

From source file:org.videolan.vlc.gui.MainActivity.java

private void showInfoDialog() {
    final Dialog infoDialog = new Dialog(this, R.style.info_dialog);
    infoDialog.setContentView(R.layout.info_dialog);
    Button okButton = (Button) infoDialog.findViewById(R.id.ok);
    okButton.setOnClickListener(new OnClickListener() {
        @Override//ww w. j  a  va 2s .c  o  m
        public void onClick(View view) {
            CheckBox notShowAgain = (CheckBox) infoDialog.findViewById(R.id.not_show_again);
            if (notShowAgain.isChecked() && mSettings != null) {
                Editor editor = mSettings.edit();
                editor.putInt(PREF_SHOW_INFO, mVersionNumber);
                editor.commit();
            }
            /* Close the dialog */
            infoDialog.dismiss();
            /* and finally open the sliding menu if first run */
            if (mFirstRun)
                mMenu.showMenu();
        }
    });
    infoDialog.show();
}

From source file:com.development.androrb.listfolders.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case 1:/* w ww. j av  a 2  s. c o  m*/
        // This example shows how to add a custom layout to an AlertDialog
        LayoutInflater factory = LayoutInflater.from(this);
        final View textEntryView = factory.inflate(R.layout.login_dialog, null);

        EditText dusernamefield = (EditText) textEntryView.findViewById(R.id.username_edit);
        dusernamefield.setText(Username);

        EditText dpasswordfield = (EditText) textEntryView.findViewById(R.id.password_edit);
        dpasswordfield.setText(Password);

        return new AlertDialog.Builder(listfolders.this).setIcon(R.drawable.alert_dialog_icon)
                .setTitle("Login Data").setView(textEntryView)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        Dialog curDialog = (Dialog) dialog;
                        EditText dusernamefield = (EditText) curDialog.findViewById(R.id.username_edit);
                        EditText dpasswordfield = (EditText) curDialog.findViewById(R.id.password_edit);
                        String dusername = dusernamefield.getText().toString();
                        String dpassword = dpasswordfield.getText().toString();

                        SharedPreferences preferences = getPreferences(MODE_PRIVATE);
                        SharedPreferences.Editor editor = preferences.edit();
                        editor.putString("UID", dusername);
                        editor.commit();
                        editor.putString("PW", dpassword);
                        editor.commit();

                        Intent mainIntent = new Intent(listfolders.this, listfolders.class);
                        listfolders.this.startActivity(mainIntent);
                        listfolders.this.finish();
                        /* User clicked OK so do some stuff */
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked cancel so do some stuff */
                    }
                }).create();
    case 2:
        // This example shows how to add a custom layout to an AlertDialog
        LayoutInflater factory2 = LayoutInflater.from(this);
        final View apiEntryView = factory2.inflate(R.layout.apikey, null);

        EditText dapikeyfield = (EditText) apiEntryView.findViewById(R.id.api_edit);
        dapikeyfield.setText(apikey);

        return new AlertDialog.Builder(listfolders.this).setIcon(R.drawable.alert_dialog_icon)
                .setTitle("API KEY").setView(apiEntryView)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        Dialog curDialog = (Dialog) dialog;
                        EditText dapikeyfield = (EditText) curDialog.findViewById(R.id.api_edit);

                        String dapikey = dapikeyfield.getText().toString();

                        SharedPreferences preferences = getPreferences(MODE_PRIVATE);
                        SharedPreferences.Editor editor = preferences.edit();

                        editor.putString("API", dapikey);
                        editor.commit();

                        Intent mainIntent = new Intent(listfolders.this, listfolders.class);
                        listfolders.this.startActivity(mainIntent);
                        listfolders.this.finish();

                        /* User clicked OK so do some stuff */
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked cancel so do some stuff */
                    }
                }).create();
    case 3:
        // This example shows how to add a custom layout to an AlertDialog
        LayoutInflater factory3 = LayoutInflater.from(this);
        final View maxEntryView = factory3.inflate(R.layout.maxcount, null);

        EditText dmaxkeyfield = (EditText) maxEntryView.findViewById(R.id.maxcount_edit);
        dmaxkeyfield.setText(maxcount);
        dmaxkeyfield.setKeyListener(new NumberKeyListener() {
            @Override
            protected char[] getAcceptedChars() {
                char[] numberChars = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };
                return numberChars;
            }

            @Override
            public int getInputType() {
                return InputType.TYPE_CLASS_NUMBER;
            }
        });

        return new AlertDialog.Builder(listfolders.this).setIcon(R.drawable.alert_dialog_icon)
                .setTitle("Max Item p.Page").setView(maxEntryView)
                .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        Dialog curDialog = (Dialog) dialog;
                        EditText dmaxkeyfield = (EditText) curDialog.findViewById(R.id.maxcount_edit);

                        String dmaxcount = dmaxkeyfield.getText().toString();
                        int idmaxcount = Integer.parseInt(dmaxcount);
                        if (idmaxcount < 10)
                            dmaxcount = "10";
                        if (idmaxcount > 500)
                            dmaxcount = "500";

                        SharedPreferences preferences = getPreferences(MODE_PRIVATE);
                        SharedPreferences.Editor editor = preferences.edit();

                        editor.putString("MAX", dmaxcount);
                        editor.commit();

                        Intent mainIntent = new Intent(listfolders.this, listfolders.class);
                        listfolders.this.startActivity(mainIntent);
                        listfolders.this.finish();

                        /* User clicked OK so do some stuff */
                    }
                }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {

                        /* User clicked cancel so do some stuff */
                    }
                }).create();
    }
    return null;
}

From source file:com.orange.datavenue.StreamListFragment.java

/**
 *
 */// w ww.  j  a  va 2  s  .co m
private void createStream() {
    final android.app.Dialog dialog = new android.app.Dialog(getActivity());

    dialog.setContentView(R.layout.create_stream_dialog);

    dialog.setTitle(R.string.add_stream);

    final LinearLayout callbackLayout = (LinearLayout) dialog.findViewById(R.id.callback_layout);
    final EditText name = (EditText) dialog.findViewById(R.id.name);
    final EditText description = (EditText) dialog.findViewById(R.id.description);
    final EditText unit = (EditText) dialog.findViewById(R.id.unit);
    final EditText symbol = (EditText) dialog.findViewById(R.id.symbol);
    final EditText callback = (EditText) dialog.findViewById(R.id.callback);
    final EditText latitude = (EditText) dialog.findViewById(R.id.latitude);
    final EditText longitude = (EditText) dialog.findViewById(R.id.longitude);

    Button actionButton = (Button) dialog.findViewById(R.id.add_button);

    callbackLayout.setVisibility(View.VISIBLE);
    actionButton.setText(getString(R.string.add_stream));

    actionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.d(TAG_NAME, "name : " + name.getText().toString());
            Log.d(TAG_NAME, "description : " + description.getText().toString());
            Log.d(TAG_NAME, "unit : " + unit.getText().toString());
            Log.d(TAG_NAME, "symbol : " + symbol.getText().toString());

            Stream newStream = new Stream();

            newStream.setName(name.getText().toString());
            newStream.setDescription(description.getText().toString());

            /**
             * Allocate new Location
             */
            Double[] location = null;

            String strLatitude = latitude.getText().toString();
            String strLongitude = longitude.getText().toString();

            try {
                if ((!"".equals(strLatitude)) && (!"".equals(strLongitude))) {
                    location = new Double[2];
                    location[0] = Double.parseDouble(strLatitude);
                    location[1] = Double.parseDouble(strLongitude);
                }
            } catch (NumberFormatException e) {
                Log.e(TAG_NAME, e.toString());
                location = null;
            }

            if (location != null) {
                newStream.setLocation(location);
            }
            /**************************************************************************/

            /**
             * Allocate new Unit & Symbol
             */
            Unit newUnit = null;
            String strUnit = unit.getText().toString();
            String strSymbol = symbol.getText().toString();

            if (!"".equals(strUnit)) {
                if (newUnit == null) {
                    newUnit = new Unit();
                }
                newUnit.setName(strUnit);
            }

            if (!"".equals(strSymbol)) {
                if (newUnit == null) {
                    newUnit = new Unit();
                }
                newUnit.setSymbol(strSymbol);
            }

            if (newUnit != null) {
                newStream.setUnit(newUnit);
            }

            /**
             * Allocate new Callback
             */
            Callback newCallback = null;
            String callbackUrl = callback.getText().toString();

            if (!"".equals(callbackUrl)) {
                try {
                    URL url = new URL(callbackUrl);
                    newCallback = new Callback();
                    newCallback.setUrl(url.toString());
                    newCallback.setName("Callback");
                    newCallback.setDescription("application callback");
                    newCallback.setStatus("activated");
                } catch (MalformedURLException e) {
                    Log.e(TAG_NAME, e.toString());
                    callback.setText("");
                }
            }

            if (newCallback != null) {
                newStream.setCallback(newCallback);
            }

            /**************************************************************************/

            CreateStreamOperation createStreamOperation = new CreateStreamOperation(Model.instance.oapiKey,
                    Model.instance.key, Model.instance.currentDatasource, newStream, new OperationCallback() {
                        @Override
                        public void process(Object object, Exception exception) {
                            if (exception == null) {
                                getStreams();
                            } else {
                                Errors.displayError(getActivity(), exception);
                            }
                        }
                    });

            createStreamOperation.execute("");

            dialog.dismiss();

        }
    });

    Button cancelButton = (Button) dialog.findViewById(R.id.cancel_button);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            dialog.dismiss();
        }
    });

    dialog.setCancelable(false);
    dialog.show();
}

From source file:com.github.howeyc.slideshow.activities.SettingsActivity.java

/************************************************************************************
*   needed because else the nested preference screen don't have a actionbar/toolbar *
*   see the fix and the given problem here: http://stackoverflow.com/a/27455363     *
************************************************************************************/
public void setUpNestedScreen(PreferenceScreen preferenceScreen) {
    final Dialog dialog = preferenceScreen.getDialog();
    //ViewGroup list;
    Toolbar bar;/*from   ww w.  ja  v  a 2s . c  o  m*/
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        //list = (ViewGroup) dialog.findViewById(android.R.id.list);
        LinearLayout root = (LinearLayout) dialog.findViewById(android.R.id.list).getParent();
        bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);
        root.addView(bar, 0); // insert at top
    } else {
        ViewGroup root = (ViewGroup) dialog.findViewById(android.R.id.content);
        ListView content = (ListView) root.getChildAt(0);
        //list = content;
        root.removeAllViews();
        bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.settings_toolbar, root, false);

        int height;
        TypedValue tv = new TypedValue();
        if (getTheme().resolveAttribute(R.attr.actionBarSize, tv, true)) {
            height = TypedValue.complexToDimensionPixelSize(tv.data, getResources().getDisplayMetrics());
        } else {
            height = bar.getHeight();
        }

        content.setPadding(0, height, 0, 0);

        root.addView(content);
        root.addView(bar);
    }
    //list.addView(detailsPrefScreenToAdd.getStatusViewGroup(), 1); //TODO
    bar.setTitle(preferenceScreen.getTitle());
    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialogI) {
            if (AppData.getLoginSuccessful()) {
                dialogI.dismiss();
            } else {
                showNotConnectedDialog(dialog);
            }
        }
    });
    bar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (AppData.getLoginSuccessful()) {
                dialog.dismiss();
            } else {
                showNotConnectedDialog(dialog);
            }
        }
    });
}