1

I have an EditText input field that needs to accept multiple email addresses.
e.g. on multiple lines.
however by setting android:inputType="textMultiLine|textEmailAddress"
the textEmailAddress options stops multiple lines being entered.
I've searched google and SO and all the "solutions" do not fix this.
Whats a working solution?

Hector
  • 4,016
  • 21
  • 112
  • 211

5 Answers5

1

Try this....It's working for me

  1. android:singleLine="false"
  2. android:lines="10" //max lines
  3. android:minLines = "3" // This will be the height

have a look at this EditText

  <EditText
    android:id="@+id/addr_edittext"
    android:layout_width="fill_parent"
    android:layout_height="150dp"
    android:gravity="top|left"
    android:inputType="textEmailAddress|textMultiLine"
    android:lines="20"
    android:minLines="5"
    android:scrollHorizontally="false"
    android:scrollbars="vertical"
    android:singleLine="false" />
Kailash Ahirwar
  • 771
  • 3
  • 14
1

however by setting android:inputType="textMultiLine|textEmailAddress" the textEmailAddress options stops multiple lines being entered.

textEmailAddress and textMultiline are hints to the IME (input method editor). There are many input method editors available on Android devices, and not all will necessarily honor things the way that you want. I am not terribly surprised that textEmailAddress and textMultiline will not work together on some IMEs.

Here are some options:

  1. Just use textMultiline and hope the user does not attack you with pitchforks for the hassle of getting to the @ key.

  2. Use more than one EditText widget. For example, you might have one (or a couple) of textEmailAddress EditText widgets, plus a + ImageButton to add more, collecting one address per EditText.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • its not just the "hassle" of entering "@" textEmailAddress also gives the .com key, i am also looking at adding in keys for .gmail etc. I am trying to create a NOTEPAD application that allows the user to enter Multiples of many types of text input, this means i will only present a single input field – Hector Sep 21 '13 at 16:05
  • @user423199: "its not just the "hassle" of entering "@" textEmailAddress also gives the .com key" -- both `@` and `.com` will vary by IME and will not always be present, even if you have `textEmailAddress`. "i am also looking at adding in keys for .gmail etc." -- you will have to write your own IME for that and ask users to use it. "I am trying to create a NOTEPAD application" -- a notepad should not use `textEmailAddress`, IMHO, since notes are not always email addresses. – CommonsWare Sep 21 '13 at 16:13
  • commonsware, thanks for taking the time to look at this, ... maybe referring to my app as a "NOTEPAD" was too vague. i realise i will have to write my own IME to deploy with my "NOTEPAD", i may look at creating a custom EditText field to "work round" this feature to allow multiple email addresses – Hector Sep 21 '13 at 16:17
  • @user423199: since the behavior of the IME is up to the implementer of the IME, if you are creating your own, you can address the `textMultiline|textEmailAddress` there. However, bear in mind that expecting users to switch to your IME to use your app may not prove to be popular. – CommonsWare Sep 21 '13 at 16:29
  • i realise the IME options is a "Stretch" – Hector Sep 21 '13 at 16:41
0

Have you set the MaxLine attribute for EditText

Try this code:

  <EditText
    android:inputType="textMultiLine" <!-- Multiline input -->
    android:lines="8" <!-- Total Lines prior display -->
    android:minLines="6" <!-- Minimum lines -->
    android:gravity="top|left" <!-- Cursor Position -->
    android:maxLines="10" <!-- Maximum Lines -->
    android:layout_height="wrap_content" <!-- Height determined by content -->
    android:layout_width="fill_parent" <!-- Fill entire width -->
    android:scrollbars="vertical" <!-- Vertical Scroll Bar -->
    android:singleLine="false" <!--Enables insertion of new line with "enter" -->
  />
Umer Farooq
  • 7,356
  • 7
  • 42
  • 67
  • yes this works fine... however i also need to set textEmailAddress, which "breaks" the multi line – Hector Sep 21 '13 at 15:51
  • sorry i didn't get you. Can you elaborate a little. – Umer Farooq Sep 21 '13 at 15:54
  • @user423199 the email address is an atomic thing it doesn't break in multiline – Trikaldarshiii Sep 21 '13 at 15:54
  • i dont want to break an email address... i need to enter more than one email address in a single edittext field – Hector Sep 21 '13 at 15:58
  • this code doesn't fulfil my needs as it doesn't allow multiple email addresses, as the "New Line" key is visible, however you cannot insert a new line inside an edittext input field that has an input type of textEmailAddress – Hector Sep 21 '13 at 16:23
0

If you are looking to add multiple recipient like gmail or any email...

Please go though the similar post

Android EditText Gmail like to field

Or You can make Multiple E-mail Autocomplete TextView.

public class ContactsAutoComplete extends AutoCompleteTextView {

    public ContactsAutoComplete(final Context context, final AttributeSet attrs,
            final int defStyle) {
        super(context, attrs, defStyle);
        this.setThreshold(0);
        this.setUpContacts();
    }

    public ContactsAutoComplete(final Context context, final AttributeSet attrs) {
        super(context, attrs);
        this.setThreshold(0);
        this.setUpContacts();
    }

    public ContactsAutoComplete(final Context context) {
        super(context);
        this.setThreshold(0);
        this.setUpContacts();
    }

    // --- comma separating stuff

    private String previous = ""; //$NON-NLS-1$
    private String seperator = ", "; //$NON-NLS-1$

    /**
     * This method filters out the existing text till the separator and launched
     * the filtering process again
     */
    @Override
    protected void performFiltering(final CharSequence text, final int keyCode) {
        String filterText = text.toString().trim();
        previous = filterText.substring(0,
                filterText.lastIndexOf(getSeperator()) + 1);
        filterText = filterText.substring(filterText.lastIndexOf(getSeperator()) + 1);
        if (!TextUtils.isEmpty(filterText)) {
            super.performFiltering(filterText, keyCode);
        }
    }

    /**
     * After a selection, capture the new value and append to the existing text
     */
    @Override
    protected void replaceText(final CharSequence text) {
        super.replaceText(previous + text + getSeperator());
    }

    public String getSeperator() {
        return seperator;
    }

    public void setSeperator(final String seperator) {
        this.seperator = seperator;
    }

    // --- contacts stuff

    private void setUpContacts() {
        ContactListAdapter adapter = new ContactListAdapter(getContext(), null);
        setAdapter(adapter);
    }

    @SuppressWarnings("nls")
    public static class ContactListAdapter extends CursorAdapter implements Filterable {
        public ContactListAdapter(Context context, Cursor c) {
            super(context, c);
            mContent = context.getContentResolver();
        }

        @Override
        public View newView(Context context, Cursor cursor, ViewGroup parent) {
            final LayoutInflater inflater = LayoutInflater.from(context);
            final TextView view = (TextView) inflater.inflate(
                    android.R.layout.simple_dropdown_item_1line, parent, false);
            view.setText(convertToString(getCursor()));
            return view;
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            ((TextView) view).setText(convertToString(cursor));
        }

        @Override
        public String convertToString(Cursor cursor) {
            return cursor.getString(1) + " <" + cursor.getString(2) +">";
        }

        @Override
        public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
            if (getFilterQueryProvider() != null) {
                return getFilterQueryProvider().runQuery(constraint);
            }

            StringBuilder buffer = null;
            String[] args = null;
            if (constraint != null) {
                constraint = constraint.toString().trim();
                buffer = new StringBuilder();
                buffer.append("UPPER(").append(People.NAME).append(") GLOB ?");
                buffer.append(" OR ");
                buffer.append("UPPER(").append(ContactMethods.DATA).append(") GLOB ?");
                args = new String[] { constraint.toString().toUpperCase() + "*",
                        constraint.toString().toUpperCase() + "*" };
            }

            return mContent.query(Contacts.ContactMethods.CONTENT_EMAIL_URI,
                    PEOPLE_PROJECTION, buffer == null ? null : buffer.toString(), args,
                    Contacts.People.DEFAULT_SORT_ORDER);
        }

        private final ContentResolver mContent;
    }

    private static final String[] PEOPLE_PROJECTION = new String[] {
        People._ID,
        People.NAME,
        ContactMethods.DATA
    };
}

Use This Custom AutoCompleteTextView like below

<YOUR_PACKAGE.ContactsAutoComplete
        android:id="@+id/emails"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="Send To"
        android:scrollbars="vertical"
        android:singleLine="false" />

Add this permission

<uses-permission android:name="android.permission.READ_CONTACTS" />

Please refer below blog.

http://www.betaful.com/2011/02/multiple-e-mail-autocomplete-in-android/

Hope this will help you.

Community
  • 1
  • 1
Amit Gupta
  • 8,914
  • 1
  • 25
  • 33
-1
android:inputType="textMultiLine|textEmailAddress"

make single line as false.this will allow multiple lines in your edit text.

khubaib
  • 535
  • 4
  • 12