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:adventure_fragments.Kayaking.java

public void AddItemNow() {
    final EditText input;

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Add item to list");
    input = new EditText(getActivity());
    int maxLength = 20;
    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });

    builder.setView(input);//from   w  w w.j av  a2s. c  o m
    builder.setPositiveButton("Add item", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String item_name = input.getText().toString();

            if (item_name.equals("")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals(" ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("  ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("This app sucks")) {
                Toast.makeText(getActivity(), "No it doesn't!", Toast.LENGTH_SHORT).show();
            } else {

                ItemClass itemClass = new ItemClass(item_name, 0);
                db.addItemKayaking(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsKayaking();
                adapt = new CustomAdapter3(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_kayak);
                listItem.setAdapter(adapt);
                count = listItem.getCount();
                if (count > 0) {
                    nothingtext.setVisibility(View.GONE);
                } else if (count == 0) {
                    nothingtext.setVisibility(View.VISIBLE);
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    builder.show();
}

From source file:adventure_fragments.Swimming.java

public void AddItemNow() {
    final EditText input;

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Add item to list");
    input = new EditText(getActivity());
    int maxLength = 20;
    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });

    builder.setView(input);// w  w  w  .ja  v  a2 s. co m
    builder.setPositiveButton("Add item", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String item_name = input.getText().toString();

            if (item_name.equals("")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals(" ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("  ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("This app sucks")) {
                Toast.makeText(getActivity(), "No it doesn't!", Toast.LENGTH_SHORT).show();
            } else {

                ItemClass itemClass = new ItemClass(item_name, 0);
                db.addItemSwimming(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsSwimming();
                adapt = new CustomAdapter6(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_swim);
                listItem.setAdapter(adapt);
                nothingtext = (TextView) rootView.findViewById(R.id.nothing_here_swim);
                count = listItem.getCount();
                if (count > 0) {
                    nothingtext.setVisibility(View.GONE);
                } else if (count == 0) {
                    nothingtext.setVisibility(View.VISIBLE);
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.show();
}

From source file:adventure_fragments.Camping.java

public void AddItemNow() {
    final EditText input;

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Add item to list");
    input = new EditText(getActivity());
    int maxLength = 20;
    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });

    builder.setView(input);//from   w w w  .  j  a va  2s  . c  o  m
    builder.setPositiveButton("Add item", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String item_name = input.getText().toString();

            if (item_name.equals("")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals(" ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("  ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("This app sucks")) {
                Toast.makeText(getActivity(), "No it doesn't!", Toast.LENGTH_SHORT).show();
            } else {

                ItemClass itemClass = new ItemClass(item_name, 0);
                db.addItemCamping(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsCamping();
                adapt = new CustomAdapter1(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_camp);
                listItem.setAdapter(adapt);
                count = listItem.getCount();
                if (count > 0) {
                    nothingtext.setVisibility(View.GONE);
                } else if (count == 0) {
                    nothingtext.setVisibility(View.VISIBLE);
                }

            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            list = db.getAllItemsCamping();
            adapt = new CustomAdapter1(getActivity(), R.layout.item_layout, list);
            listItem = (ListView) getActivity().findViewById(R.id.listview_camp);
            listItem.setAdapter(adapt);

            dialog.dismiss();
        }
    });

    builder.show();
}

From source file:adventure_fragments.Climbing.java

public void AddItemNow() {
    final EditText input;

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Add item to list");
    input = new EditText(getActivity());
    int maxLength = 20;
    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });

    builder.setView(input);// w ww  .ja v  a  2s.  c  om
    builder.setPositiveButton("Add item", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String item_name = input.getText().toString();

            if (item_name.equals("")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals(" ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("  ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("This app sucks")) {
                Toast.makeText(getActivity(), "No it doesn't!", Toast.LENGTH_SHORT).show();
            } else {

                ItemClass itemClass = new ItemClass(item_name, 0);
                db.addItemClimbing(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsClimbing();
                adapt = new CustomAdapter1(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_climb);
                listItem.setAdapter(adapt);
                count = listItem.getCount();
                if (count > 0) {
                    nothingtext.setVisibility(View.GONE);
                } else if (count == 0) {
                    nothingtext.setVisibility(View.VISIBLE);
                }

            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            list = db.getAllItemsClimbing();
            adapt = new CustomAdapter1(getActivity(), R.layout.item_layout, list);
            listItem = (ListView) getActivity().findViewById(R.id.listview_climb);
            listItem.setAdapter(adapt);

            dialog.dismiss();
        }
    });

    builder.show();
}

From source file:adventure_fragments.Biking.java

public void AddItemNow() {
    final EditText input;

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    builder.setTitle("Add item to list");
    input = new EditText(getActivity());
    int maxLength = 20;
    input.setFilters(new InputFilter[] { new InputFilter.LengthFilter(maxLength) });

    builder.setView(input);/*from  w  w w . j  a va 2 s.c om*/
    builder.setPositiveButton("Add item", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            String item_name = input.getText().toString();

            if (item_name.equals("")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals(" ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("  ")) {
                Toast.makeText(getActivity(), "Please enter a name for the item", Toast.LENGTH_SHORT).show();
            } else if (item_name.equals("This app sucks")) {
                Toast.makeText(getActivity(), "No it doesn't!", Toast.LENGTH_SHORT).show();
            }

            else {

                ItemClass itemClass = new ItemClass(item_name, 0);
                db.addItemBiking(itemClass);
                adapt.add(itemClass);
                adapt.notifyDataSetChanged();
                list = db.getAllItemsBiking();
                adapt = new CustomAdapter(getActivity(), R.layout.item_layout, list);
                listItem = (ListView) getActivity().findViewById(R.id.listview_bike);
                listItem.setAdapter(adapt);
                nothingtext = (TextView) rootView.findViewById(R.id.nothing_here_bike);
                count = listItem.getCount();
                if (count > 0) {
                    nothingtext.setVisibility(View.GONE);
                } else if (count == 0) {
                    nothingtext.setVisibility(View.VISIBLE);
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.show();
}

From source file:ch.hearc.drunksum.DrunkSumActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    /*//from w  ww.  j  a v a  2s  .  c o  m
    Gre le clic sur un lment du menu
     */
    if (item.getItemId() == R.id.reinit) {
        // remet la somme  0
        Toast.makeText(this, "Sum reinitialized", Toast.LENGTH_SHORT).show();
        mSum = 0;
        setTitle("Sum: " + formatter.format(mSum));
    } else if (item.getItemId() == R.id.divide) {
        // propose de divisier la somme
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        alert.setTitle("Divide sum by:");
        final EditText input = new EditText(this);
        // n'afficher que les chiffres
        input.setInputType(InputType.TYPE_CLASS_NUMBER);
        alert.setView(input);
        alert.setPositiveButton("Divide", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                double div = 0;
                try {
                    // une exception survient si le texte est vide
                    // si c'est 0, div vaut infinity
                    div = mSum / Double.parseDouble(input.getText().toString());
                } catch (Exception e) {
                }

                final Snackbar snackBar = Snackbar.make(mGraphicOverlay,
                        "Divided sum: " + formatter.format(div), Snackbar.LENGTH_INDEFINITE);

                snackBar.setAction("OK", new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        snackBar.dismiss();
                    }
                });
                snackBar.show();
            }
        });
        alert.show();
    }

    return true;
}

From source file:com.tinfoil.sms.sms.KeyExchangeManager.java

/**
 * Set the shared secrets for the contacts.
 * @param context The context of the setting.
 * @param number The Number of the contact.
 * @param name The name of the contact/*  ww  w  . j av  a2 s .c  o m*/
 * @param entry The key exchange message.
 */
private static void setAndSend(final Context context, final Number number, String name, final Entry entry) {
    final DBAccessor dba = new DBAccessor(context);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);

    final EditText sharedSecret1 = new EditText(context);
    sharedSecret1.setHint(context.getString(R.string.shared_secret_hint_1));
    sharedSecret1.setMaxLines(EditNumber.SHARED_INFO_MAX);
    sharedSecret1.setInputType(InputType.TYPE_CLASS_TEXT);
    linearLayout.addView(sharedSecret1);

    final EditText sharedSecret2 = new EditText(context);
    sharedSecret2.setHint(context.getString(R.string.shared_secret_hint_2));
    sharedSecret2.setMaxLines(EditNumber.SHARED_INFO_MAX);
    sharedSecret2.setInputType(InputType.TYPE_CLASS_TEXT);
    linearLayout.addView(sharedSecret2);

    builder.setMessage(context.getString(R.string.set_shared_secrets) + " " + name + ", " + number.getNumber())
            .setTitle(R.string.set_shared_secrets_title).setCancelable(true)
            .setPositiveButton(R.string.save, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int id) {
                    //Save the shared secrets
                    String s1 = sharedSecret1.getText().toString();
                    String s2 = sharedSecret2.getText().toString();
                    if (SMSUtility.checksharedSecret(s1) && SMSUtility.checksharedSecret(s2)) {
                        number.setSharedInfo1(s1);
                        number.setSharedInfo2(s2);
                        dba.updateNumberRow(number, number.getNumber(), number.getId());

                        respondKeyExchangeMessage(context, number, entry);
                    } else {
                        Toast.makeText(context, R.string.invalid_secrets, Toast.LENGTH_LONG).show();
                    }
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface arg0, int arg1) {
                    //Cancel the key exchange
                    Toast.makeText(context, R.string.key_exchange_cancelled, Toast.LENGTH_LONG).show();
                }
            });
    AlertDialog alert = builder.create();

    alert.setView(linearLayout);
    alert.show();
}

From source file:id.satusatudua.sigap.ui.fragment.TrustedsFragment.java

@OnClick(R.id.fab)
public void addNewContact() {
    EditText editText = new EditText(getActivity());
    editText.setHint("Email");
    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
    AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).setIcon(R.mipmap.ic_launcher)
            .setTitle("Masukan alamat email kontak").setView(editText)
            .setPositiveButton("Kirim", (dialog, which) -> {
                String email = editText.getText().toString();

                if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
                    showError("Mohon masukan alamat email yang valid!");
                } else if (email.equalsIgnoreCase(CacheManager.pluck().getCurrentUser().getEmail())) {
                    showError("Mohon masukan alamat email selain email anda sendiri!");
                } else {
                    trustedUserPresenter.searchUser(email);
                    KeyboardUtil.hideKeyboard(getActivity(), editText);
                    dialog.dismiss();/*from  w  w  w. j  ava  2  s .  c o  m*/
                }
            }).setNegativeButton("Batal", (dialog, which1) -> {
                dialog.dismiss();
            }).show();

    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE)
            .setTextColor(ContextCompat.getColor(getActivity(), R.color.colorPrimary));
    alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE)
            .setTextColor(ContextCompat.getColor(getActivity(), R.color.primary_text));
    alertDialog.show();
}

From source file:com.tinfoil.sms.settings.UserKeySettings.java

public void exportKey(View view) {
    if (SMSUtility.isMediaWritable()) {
        phoneBook = new AutoCompleteTextView(this);
        List<String> contact = null;
        if (tc == null) {
            //Do in thread.
            tc = dba.getAllRows(DBAccessor.ALL);
        }//  w  ww . ja  v  a2  s.c o m

        if (tc != null) {
            if (contact == null) {
                contact = SMSUtility.contactDisplayMaker(tc);
            }
        } else {
            contact = null;
        }
        final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getBaseContext(),
                R.layout.auto_complete_list_item, contact);

        phoneBook.setAdapter(adapter);

        final AlertDialog.Builder popup_builder = new AlertDialog.Builder(this);
        popup_builder.setTitle(R.string.import_contacts_title).setCancelable(true).setView(phoneBook)
                .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                    public void onClick(final DialogInterface dialog, final int which) {

                        String[] contactInfo = SMSUtility.parseAutoComplete(phoneBook.getText().toString());
                        //String number = null;

                        boolean invalid = false;
                        if (contactInfo != null) {
                            if (contactInfo[0] == null) {
                                contactInfo[0] = contactInfo[1];
                            }

                            final Number number = dba.getNumber(contactInfo[1]);

                            if (number != null) {
                                AlertDialog.Builder builder = new AlertDialog.Builder(UserKeySettings.this);
                                LinearLayout linearLayout = new LinearLayout(UserKeySettings.this);
                                linearLayout.setOrientation(LinearLayout.VERTICAL);

                                final EditText sharedSecret1 = new EditText(UserKeySettings.this);
                                sharedSecret1
                                        .setHint(UserKeySettings.this.getString(R.string.shared_secret_hint_1));
                                sharedSecret1.setMaxLines(EditNumber.SHARED_INFO_MAX);
                                sharedSecret1.setInputType(InputType.TYPE_CLASS_TEXT);
                                linearLayout.addView(sharedSecret1);

                                final EditText sharedSecret2 = new EditText(UserKeySettings.this);
                                sharedSecret2
                                        .setHint(UserKeySettings.this.getString(R.string.shared_secret_hint_2));
                                sharedSecret2.setMaxLines(EditNumber.SHARED_INFO_MAX);
                                sharedSecret2.setInputType(InputType.TYPE_CLASS_TEXT);
                                linearLayout.addView(sharedSecret2);

                                builder.setMessage(UserKeySettings.this.getString(R.string.set_shared_secrets)
                                        + " " + contactInfo[0] + ", " + number.getNumber())
                                        .setTitle(R.string.set_shared_secrets_title).setCancelable(true)
                                        .setPositiveButton(R.string.save,
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface dialog, int id) {
                                                        //Save the shared secrets

                                                        String s1 = sharedSecret1.getText().toString();
                                                        String s2 = sharedSecret2.getText().toString();
                                                        if (SMSUtility.checksharedSecret(s1)
                                                                && SMSUtility.checksharedSecret(s2)) {
                                                            number.setSharedInfo1(s1);
                                                            number.setSharedInfo2(s2);
                                                            dba.updateNumberRow(number, number.getNumber(),
                                                                    number.getId());

                                                            number.setInitiator(true);
                                                            dba.updateInitiator(number);

                                                            //TODO add check for shared secrets
                                                            String keyExchangeMessage = KeyExchange.sign(number,
                                                                    dba, SMSUtility.user);

                                                            writeToFile(number.getNumber(), keyExchangeMessage);

                                                            Toast.makeText(UserKeySettings.this,
                                                                    UserKeySettings.this
                                                                            .getString(R.string.written_path)
                                                                            + " " + path + "/"
                                                                            + number.getNumber() + "_" + file,
                                                                    Toast.LENGTH_SHORT).show();

                                                        } else {
                                                            Toast.makeText(UserKeySettings.this,
                                                                    R.string.invalid_secrets, Toast.LENGTH_LONG)
                                                                    .show();
                                                        }
                                                    }
                                                })
                                        .setNegativeButton(android.R.string.cancel,
                                                new DialogInterface.OnClickListener() {
                                                    @Override
                                                    public void onClick(DialogInterface arg0, int arg1) {
                                                        //Cancel the key exchange
                                                        Toast.makeText(UserKeySettings.this,
                                                                R.string.key_exchange_cancelled,
                                                                Toast.LENGTH_LONG).show();
                                                    }
                                                });
                                AlertDialog alert = builder.create();

                                alert.setView(linearLayout);
                                alert.show();
                            } else {
                                invalid = true;
                            }
                        } else {
                            invalid = true;
                        }

                        if (invalid) {
                            Toast.makeText(UserKeySettings.this, R.string.invalid_number_message,
                                    Toast.LENGTH_LONG).show();
                        }
                    }
                });

        popup_alert = popup_builder.create();
        popup_alert.show();

        //getExternalFilesDir(null);
    }
}

From source file:com.morlunk.mumbleclient.servers.PublicServerListFragment.java

@Override
public void favouriteServer(final Server server) {
    final Settings settings = Settings.getInstance(getActivity());
    final EditText usernameField = new EditText(getActivity());
    usernameField.setHint(settings.getDefaultUsername());
    AlertDialog.Builder adb = new AlertDialog.Builder(getActivity());
    adb.setTitle(R.string.addFavorite);//from  www.j a  va2  s  .  c  om
    adb.setView(usernameField);
    adb.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (usernameField.getText().length() > 0) {
                server.setUsername(usernameField.getText().toString());
            } else {
                server.setUsername(settings.getDefaultUsername());
            }
            PlumbleDatabase database = mDatabaseProvider.getDatabase();
            database.addServer(server);
        }
    });
    adb.setNegativeButton(android.R.string.cancel, null);
    adb.show();
}