Example usage for android.widget EditText EditText

List of usage examples for android.widget EditText EditText

Introduction

In this page you can find the example usage for android.widget EditText EditText.

Prototype

public EditText(Context context) 

Source Link

Usage

From source file:com.andrew.apollo.menu.PlaylistDialog.java

@Override
public void onCreate(Bundle icicle) {

    super.onCreate(icicle);
    setContentView(new LinearLayout(this));

    action = getIntent().getAction();/*  w ww . jav a2 s  . co  m*/

    mRenameId = icicle != null ? icicle.getLong(INTENT_KEY_RENAME)
            : getIntent().getLongExtra(INTENT_KEY_RENAME, -1);
    mList = icicle != null ? icicle.getLongArray(INTENT_PLAYLIST_LIST)
            : getIntent().getLongArrayExtra(INTENT_PLAYLIST_LIST);
    if (INTENT_RENAME_PLAYLIST.equals(action)) {
        mOriginalName = nameForId(mRenameId);
        mDefaultName = icicle != null ? icicle.getString(INTENT_KEY_DEFAULT_NAME) : mOriginalName;
    } else if (INTENT_CREATE_PLAYLIST.equals(action)) {
        mDefaultName = icicle != null ? icicle.getString(INTENT_KEY_DEFAULT_NAME) : makePlaylistName();
        mOriginalName = mDefaultName;
    }

    DisplayMetrics dm = new DisplayMetrics();
    dm = getResources().getDisplayMetrics();

    mPlaylistDialog = new AlertDialog.Builder(this).create();
    mPlaylistDialog.setVolumeControlStream(AudioManager.STREAM_MUSIC);

    if (action != null && mRenameId >= 0 && mOriginalName != null || mDefaultName != null) {

        mPlaylist = new EditText(this);
        mPlaylist.setSingleLine(true);
        mPlaylist.setText(mDefaultName);
        mPlaylist.setSelection(mDefaultName.length());
        mPlaylist.addTextChangedListener(this);

        mPlaylistDialog.setIcon(android.R.drawable.ic_dialog_info);
        String promptformat;
        String prompt = "";
        if (INTENT_RENAME_PLAYLIST.equals(action)) {
            promptformat = getString(R.string.rename_playlist);
            prompt = String.format(promptformat, mOriginalName, mDefaultName);
        } else if (INTENT_CREATE_PLAYLIST.equals(action)) {
            promptformat = getString(R.string.new_playlist);
            prompt = String.format(promptformat, mDefaultName);
        }

        mPlaylistDialog.setTitle(prompt);
        mPlaylistDialog.setView(mPlaylist, (int) (8 * dm.density), (int) (8 * dm.density),
                (int) (8 * dm.density), (int) (4 * dm.density));
        if (INTENT_RENAME_PLAYLIST.equals(action)) {
            mPlaylistDialog.setButton(Dialog.BUTTON_POSITIVE, getString(R.string.save),
                    mRenamePlaylistListener);
            mPlaylistDialog.setOnShowListener(this);
        } else if (INTENT_CREATE_PLAYLIST.equals(action)) {
            mPlaylistDialog.setButton(Dialog.BUTTON_POSITIVE, getString(R.string.save),
                    mCreatePlaylistListener);
        }
        mPlaylistDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(android.R.string.cancel),
                new OnClickListener() {

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

                        finish();
                    }
                });
        mPlaylistDialog.setOnCancelListener(this);
        mPlaylistDialog.show();
    } else {
        Toast.makeText(this, R.string.error, Toast.LENGTH_SHORT).show();
        finish();
    }

}

From source file:com.loloof64.android.capturing_audio.MainActivity.java

public void recordingButtonClicked(View view) {
    try {//from ww w.  j a v  a  2 s .co  m
        recorderFragment.toggleRecordingState();
    } catch (IOException e) {
        Log.e("RecordingAudio", e.getMessage(), e);
        ///////////////////////////////////////////////////////////////////////
        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
        dialogBuilder.setTitle("Error");

        ScrollView scrollingView = new ScrollView(dialogBuilder.getContext());
        scrollingView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        EditText textView = new EditText(dialogBuilder.getContext());
        textView.setLayoutParams(new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        textView.setText(Arrays.toString(e.getStackTrace()));

        scrollingView.addView(textView);
        dialogBuilder.setView(scrollingView);

        dialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialogBuilder.show();
        ////////////////////////////////////////////////////////////////////////
        Toast.makeText(this, R.string.could_not_create_temporary_file, Toast.LENGTH_SHORT).show();
    }
}

From source file:de.gadc.moneybeam.MoneyBeamActivity.java

/**
 * This method presents the user the dialog that enables him to enter his
 * email address./*  ww w. j  a v a 2 s  . c  om*/
 */
private void showEmailDialog() {
    final EditText editText = new EditText(this);
    AlertDialog.Builder emailDialogBuilder = new Builder(this);
    emailDialogBuilder.setTitle(R.string.hint_email);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    editText.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
    emailDialogBuilder.setView(editText);
    emailDialogBuilder.setPositiveButton(R.string.button_ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String mail = editText.getText().toString();
            prefs.edit().putString(Configuration.PREF_MAIL, mail).commit();
        }
    });
    emailDialogBuilder.setNegativeButton(R.string.button_cancel, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    emailDialogBuilder.show();
}

From source file:mobile.client.iot.pzalejko.iothome.MainActivity.java

private void askForNewTemperatureAlert() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getString(R.string.alert_dialog_title_text));

    final EditText input = new EditText(this);
    input.setInputType(InputType.TYPE_CLASS_NUMBER);
    builder.setView(input);//from   w ww . j  a  va2  s .  c om

    builder.setPositiveButton(getString(R.string.alert_dialog_update_button_text),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    tempAlertValueText.setText(R.string.empty_text_marker);

                    Double alertValue = Double.parseDouble(input.getText().toString());
                    TemperatureAlertEntity entity = new TemperatureAlertEntity(alertValue);

                    // send a request which will set a new temperature alert value.
                    Event event = new Event(entity, EventSource.LOCAL, EventType.UPDATE_TEMPERATURE_ALERT);
                    Intent outIntent = new Intent(MqttEvent.EVENT_OUT);
                    outIntent.putExtra(MqttEvent.PAYLOAD, event);
                    broadcaster.sendBroadcast(outIntent);
                }
            });
    builder.setNegativeButton(getString(R.string.alert_dialog_cancel_button_text),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });

    builder.show();
}

From source file:eu.hydrologis.geopaparazzi.maptools.FeaturePageAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    final Feature feature = featuresList.get(position);

    int bgColor = context.getResources().getColor(R.color.formbgcolor);
    int textColor = context.getResources().getColor(R.color.formcolor);

    ScrollView scrollView = new ScrollView(context);
    ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);// ww  w. ja  v  a 2  s . co  m
    scrollLayoutParams.setMargins(10, 10, 10, 10);
    scrollView.setLayoutParams(scrollLayoutParams);
    scrollView.setBackgroundColor(bgColor);

    LinearLayout linearLayoutView = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    int margin = 10;
    layoutParams.setMargins(margin, margin, margin, margin);
    linearLayoutView.setLayoutParams(layoutParams);
    linearLayoutView.setOrientation(LinearLayout.VERTICAL);
    int padding = 10;
    linearLayoutView.setPadding(padding, padding, padding, padding);
    scrollView.addView(linearLayoutView);

    List<String> attributeNames = feature.getAttributeNames();
    List<String> attributeValues = feature.getAttributeValuesStrings();
    List<String> attributeTypes = feature.getAttributeTypes();
    for (int i = 0; i < attributeNames.size(); i++) {
        final String name = attributeNames.get(i);
        String value = attributeValues.get(i);
        String typeString = attributeTypes.get(i);
        DataType type = DataType.getType4Name(typeString);

        TextView textView = new TextView(context);
        textView.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        textView.setPadding(padding, padding, padding, padding);
        textView.setText(name);
        textView.setTextColor(textColor);
        // textView.setTextAppearance(context, android.R.style.TextAppearance_Medium);

        linearLayoutView.addView(textView);

        final EditText editView = new EditText(context);
        LinearLayout.LayoutParams editViewParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.WRAP_CONTENT);
        editViewParams.setMargins(margin, 0, margin, 0);
        editView.setLayoutParams(editViewParams);
        editView.setPadding(padding * 2, padding, padding * 2, padding);
        editView.setText(value);
        //            editView.setEnabled(!isReadOnly);
        editView.setFocusable(!isReadOnly);
        // editView.setTextAppearance(context, android.R.style.TextAppearance_Medium);

        if (isReadOnly) {
            editView.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    String text = editView.getText().toString();
                    FeatureUtilities.viewIfApplicable(v.getContext(), text);
                    return false;
                }
            });
        }

        switch (type) {
        case DOUBLE:
        case FLOAT:
            editView.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
            break;
        case PHONE:
            editView.setInputType(InputType.TYPE_CLASS_PHONE);
            break;
        case DATE:
            editView.setInputType(InputType.TYPE_CLASS_DATETIME);
            break;
        case INTEGER:
            editView.setInputType(InputType.TYPE_CLASS_NUMBER);
            break;
        default:
            break;
        }

        editView.addTextChangedListener(new TextWatcher() {
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // ignore
            }

            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                // ignore
            }

            public void afterTextChanged(Editable s) {
                String text = editView.getText().toString();
                feature.setAttribute(name, text);
            }
        });

        linearLayoutView.addView(editView);
    }

    /*
     * add also area and length
     */
    if (feature.getOriginalArea() > -1) {
        TextView areaTextView = new TextView(context);
        areaTextView.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        areaTextView.setPadding(padding, padding, padding, padding);
        areaTextView.setText("Area: " + areaLengthFormatter.format(feature.getOriginalArea()));
        areaTextView.setTextColor(textColor);
        TextView lengthTextView = new TextView(context);
        lengthTextView.setLayoutParams(
                new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        lengthTextView.setPadding(padding, padding, padding, padding);
        lengthTextView.setText("Length: " + areaLengthFormatter.format(feature.getOriginalLength()));
        lengthTextView.setTextColor(textColor);
        linearLayoutView.addView(areaTextView);
        linearLayoutView.addView(lengthTextView);
    }
    container.addView(scrollView);

    return scrollView;
}

From source file:com.secbro.qark.exportedcomponent.exportedreceiver.IntentSenderFragment.java

private void createKeyValuePairLayout(String key, LinearLayout paramsLayout) {
    LinearLayout linearLayout = new LinearLayout(getActivity());
    linearLayout.setOrientation(LinearLayout.HORIZONTAL);

    LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    llp.setMargins(50, 10, 50, 10); // llp.setMargins(left, top, right, bottom);
    TextView keyTextView = new TextView(getActivity());
    keyTextView.setTag("key" + key);
    keyTextView.setText(key);/*  w w  w  .j  a  v  a  2 s  .com*/
    keyTextView.setLayoutParams(llp);

    LinearLayout.LayoutParams llp1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    llp.setMargins(50, 10, 50, 10); // llp.setMargins(left, top, right, bottom);
    EditText valueEditText = new EditText(getActivity());
    valueEditText.setTag("value" + key);
    valueEditText.setLayoutParams(llp1);

    linearLayout.addView(keyTextView);
    linearLayout.addView(valueEditText);
    paramsLayout.addView(linearLayout);
}

From source file:com.androcast.illusion.illusionmod.fragments.PathReaderFragment.java

private void showDialog(final String file, String value) {
    LinearLayout layout = new LinearLayout(getActivity());
    layout.setPadding(30, 30, 30, 30);/*w  w  w. j av  a2  s  .c o m*/

    final EditText editText = new EditText(getActivity());
    editText.setGravity(Gravity.CENTER);
    editText.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    if (!Utils.DARKTHEME)
        editText.setTextColor(getResources().getColor(R.color.black));
    editText.setText(value);

    layout.addView(editText);

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setView(layout)
            .setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            }).setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Control.runCommand(editText.getText().toString(), file, Control.CommandType.GENERIC,
                            getActivity());
                    refreshLayout.setRefreshing(true);
                    getHandler().postDelayed(refresh, 500);
                }
            }).show();
}

From source file:com.nextgis.mobile.map.RemoteTMSLayer.java

protected static void showPropertiesDialog(final MapBase map, final boolean bCreate, String layerName,
        String layerUrl, int type, final RemoteTMSLayer layer) {
    final LinearLayout linearLayout = new LinearLayout(map.getContext());
    final EditText input = new EditText(map.getContext());
    input.setText(layerName);/*from   w w w .j  a v a  2 s.  c  om*/

    final EditText url = new EditText(map.getContext());
    url.setText(layerUrl);

    final TextView stLayerName = new TextView(map.getContext());
    stLayerName.setText(map.getContext().getString(R.string.layer_name) + ":");

    final TextView stLayerUrl = new TextView(map.getContext());
    stLayerUrl.setText(map.getContext().getString(R.string.layer_url) + ":");

    final TextView stLayerType = new TextView(map.getContext());
    stLayerType.setText(map.getContext().getString(R.string.layer_type) + ":");

    final ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(map.getContext(),
            android.R.layout.simple_spinner_item);
    final Spinner spinner = new Spinner(map.getContext());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);

    adapter.add(map.getContext().getString(R.string.tmstype_osm));
    adapter.add(map.getContext().getString(R.string.tmstype_normal));
    adapter.add(map.getContext().getString(R.string.tmstype_ngw));

    if (type == TMSTYPE_OSM) {
        spinner.setSelection(0);
    } else {
        spinner.setSelection(1);
    }

    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.addView(stLayerName);
    linearLayout.addView(input);
    linearLayout.addView(stLayerUrl);
    linearLayout.addView(url);
    linearLayout.addView(stLayerType);
    linearLayout.addView(spinner);

    new AlertDialog.Builder(map.getContext())
            .setTitle(bCreate ? R.string.input_layer_properties : R.string.change_layer_properties)
            //                                    .setMessage(message)
            .setView(linearLayout).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    int tmsType = 0;
                    switch (spinner.getSelectedItemPosition()) {
                    case 0:
                    case 1:
                        tmsType = TMSTYPE_OSM;
                        break;
                    case 2:
                    case 3:
                        tmsType = TMSTYPE_NORMAL;
                        break;
                    }

                    if (bCreate) {
                        create(map, input.getText().toString(), url.getText().toString(), tmsType);
                    } else {
                        layer.setName(input.getText().toString());
                        layer.setTMSType(tmsType);
                        map.onLayerChanged(layer);
                    }
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    // Do nothing.
                    Toast.makeText(map.getContext(), R.string.error_cancel_by_user, Toast.LENGTH_SHORT).show();
                }
            }).show();
}

From source file:alexander.martinz.libs.materialpreferences.MaterialEditTextPreference.java

protected AlertDialog createAlertDialog() {
    final Context context = getContext();
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(getTitle());/* www .  j a  v  a 2  s .  c  o  m*/

    // create the wrapper layout to apply margins to the edit text
    final LinearLayout wrapper = new LinearLayout(context);
    wrapper.setOrientation(LinearLayout.VERTICAL);
    final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    final int margin = (int) convertDpToPixels(10);
    layoutParams.setMargins(margin, 0, margin, 0);

    // create the EditText and add it to the wrapper layout
    final EditText editText = new EditText(context);
    editText.setText(mValue);
    wrapper.addView(editText, layoutParams);

    // set our wrapper as view
    builder.setView(wrapper);

    builder.setNegativeButton(android.R.string.cancel, null);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final String value = editText.getText().toString();
            if (TextUtils.equals(value, mValue)) {
                // the value did not change, so lets end here
                return;
            }

            mValue = value;
            final MaterialEditTextPreference preference = MaterialEditTextPreference.this;

            if (mListener != null) {
                if (mListener.onPreferenceChanged(preference, mValue)) {
                    setText(mValue);
                }
            } else {
                setText(mValue);
            }
        }
    });

    return builder.create();
}

From source file:eu.codeplumbers.cosi.activities.NoteDetailsActivity.java

private void getNoteTitle(final SimpleDateFormat isoFormat, final Date date) {
    AlertDialog.Builder alertDialog = new AlertDialog.Builder(NoteDetailsActivity.this);
    alertDialog.setTitle("Title");
    alertDialog.setMessage("Enter note title");

    final EditText input = new EditText(NoteDetailsActivity.this);
    if (note.getTitle() != "") {
        input.setText(note.getTitle());//from  w w  w  . j a v  a 2 s.com
    }
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT);
    input.setLayoutParams(lp);
    alertDialog.setView(input);

    alertDialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            String title = input.getText().toString();
            note.setTitle(title);

            ArrayList<String> list = new ArrayList<String>();
            list.add(note.getTitle());
            note.setPath(new JSONArray(list).toString());
            note.setLastModificationDate(isoFormat.format(date));
            note.setLastModificationValueOf(String.valueOf(date.getTime()));
            note.setContent(body.getHtml());
            note.save();

            try {
                new SyncDocumentTask(NoteDetailsActivity.this).execute(note.toJsonObject());
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });

    alertDialog.show();

}