I'm working on an Android app and need to email to various users.
Currently I have an 'EditText' which is configured as:
android:inputType="textEmailAddress"
Once a button is pressed an email is sent to the address specified in this field.
But I would to create a multi address input list.
Is there a way to do it without change the 'EditText' to multiple lines and parsing the string myself?
Googled it but could not find a solution.
Any suggestions?
Thanks in advance.
There is a lines and minLines attribute in EditText. Example would be:
<EditText
android:inputType="textEmailAddress" <!-- email address -->
android:lines="8" <!-- Total Lines prior display -->
android:minLines="6" <!-- Minimum lines -->
</EditText>
See this answer for further details.
You may use a separator to separate the emails:
first_email#gmail.com, second_email#gmail.com and so on. In your code call split() method to get an array of emails from this long line.
Related
Is it possible to create an alert in the edittext?
I've seen it in 2 apps with exactly the same style, so I understand it's a default view or property.
YOu have to use https://github.com/vekexasia/android-edittext-validator
There are several values you can set to the test attribute:
regexp: for custom regexp
numeric: for an only numeric field
alpha: for an alpha only field
alphaNumeric:
personName: checks if the entered text is a person first or last name.
personFullName: checks if the entered value is a complete full name.
email: checks that the field is a valid email
creditCard: checks that the field contains a valid credit card using Luhn Algorithm
phone: checks that the field contains a valid phone number
domainName: checks that field contains a valid domain name ( always passes the test in API Level < 8 )
ipAddress: checks that the field contains a valid ip address
webUrl: checks that the field contains a valid url ( always passes the test in API Level < 8 )
date: checks that the field is a valid date/datetime format ( if customFormat is set, checks with customFormat )
nocheck: It does not check anything except the emptyness of the field.
It is possible using setError method. it is available from API Level one only.
editText.setError("Enter yor error message").
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">
<EditText
android:id="#+id/phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:hint="#string/cont_num"
android:inputType="phone"/>
</android.support.design.widget.TextInputLayout>
From the android design library
Rather than using an EditText widget one solution would be a RelativeLayout with a Auto complete TextView widget and an alert Icon of your choice set rightOf your AC TextView within the RL.
Then add a text change listener to your AC textview which is looking for your specific text input i.e. binary and if a breach is detected display warning and error icon?
Is there any way to limit users allowed to type only some selected character set (Eg: A or B or C or D) in Android layout.xml
Use the digits attribute, only the characters passed to digits will be allowed in the EditText.
android:digits="abc123"
And yes, "digits" is a misleading name, it accepts letters and symbols too.
You can use the inputType attribute:
<EditText android:id="#+id/edit_text_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="number" />
Possible Values for android:inputType attribute in edit text are: none, text, textCapCharacters, textCapWords, textCapSentences, textAutoCorrect, textAutoComplete, textMultiLine, textImeMultiLine, textNoSuggestions, textUri, textEmailAddress, textEmailSubject, textShortMessage, textLongMessage, textPersonName, textPostalAddress, textPassword, textVisiblePassword, textWebEditText, textFilter, textPhonetic, textWebEmailAddress, textWebPassword, number, numberSigned, numberDecimal, numberPassword, phone, datetime, date, time
This android:digit will allow only the digits and alphabets you want to be filled in EditText.
<EditText
android:inputType="text"
android:digits="0123456789*qwertzuiopasdfghjklyxcvbnm,_,-"
android:hint="Only letters, digits, _ and - allowed"
/>
You can set your EditText Field like this...
<EditText
android:inputType="text"
android:digits="THE SELECTED CHARACTERS THAT USERS ARE ALLOWED TO TYPE"
/>
By listing the selected characters (A,B,C,and D) that users are allowed to type in the android:digits, you are limiting the possible characters that users can type. This is the easiest way I've learned through searching.
Hi in my project i have a edit text box, where i want the user to enter his phone number, I need it in a format like +0000000000 no need to allow - or any other symbols. I need to restrict the user while entering in keyboard. I have implemented the regular expression for validation for this format and I am using android:inputType="phone" is there any other input Type is available or can i customize it in any way. Looking for help pls...
Try it android:digits="+0123456789"
try this::
android:inputType="number"
it allow user to enter only integer value
I am essentially trying to set the digits value of an EditText programmatically. So far I have:
weightInput.setInputType(InputType.TYPE_CLASS_PHONE);
weightInput.setKeyListener(DigitsKeyListener.getInstance());
Which is fine, but I also want to be able to include a decimal place (.). Any ideas?
Try this:
<EditText
android:inputType="number"
android:digits="0123456789."
/>
From Code:
weightInput.setKeyListener(DigitsKeyListener.getInstance("0123456789."));
But, it allows the user to include several "."
See JoeyRA's answer for real numbers.
Try this:
weightInput.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
weightInput.setKeyListener(DigitsKeyListener.getInstance(false,true));
public static DigitsKeyListener getInstance (boolean sign, boolean decimal)
Returns a DigitsKeyListener that accepts the digits 0 through 9, plus the minus sign (only at the beginning) and/or decimal point (only one per field) if specified.
This solve the problem about the many '.' in EditText
Use InputType.TYPE_NUMBER_FLAG_DECIMAL.
Also see: Input Types.
if anyone still finding proper way, note that its setRawInputType() not setInputType()
val digits = "ABCDabcd" // or any characters you want to allow
editText.keyListener = DigitsKeyListener.getInstance(digits)
editText.setRawInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME)
For IP address input ( Multiple dots and numbers )
try
<EditText
android:id="#+id/ipBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="#string/ipAddrHint"
android:inputType="numberDecimal|number"
android:digits="0123456789."
android:textSize="30sp" />
None of the above solutions worked as expected. Digits in xml file still allow me to put "," in the input.
Check for it, it's works for me:
edittext.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
I have a TextView with android:autoLink="email".
If I put my email address in there then a link appears that I can click.
How do I have different text appear (for example 'Send Feedback') instead of the email address but still behave the same when clicked?
Thanks
To achieve what I wanted required a different approach:
TextView feedback = (TextView) findViewById(R.id.TextViewSendFeedback);
feedback.setText(Html.fromHtml("Send Feedback"));
feedback.setMovementMethod(LinkMovementMethod.getInstance());
This basically places HTML in the TextView so I get a link saying 'Send Feedback' but clicking it opens the default email application.
Word of warning: Trying this in the emulator didn't initially work for me, saying it was unsupported. This was just because I didn't have an email account setup. Setting one up in the emulator made the link work as I wanted.
You can use both links and email if you set the following param in the TextView
android:autoLink="web|email"
the links will be opened in the browser and the mails will be sent by the default mail client
Another simple way in layout:
...
<TextView
android:id="#+id/tvTelefone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sobre_telefone"
android:textColor="#000000"
android:autoLink="phone" />
...
...
<string name="sobre_telefone">Contato: (45) 9145-0000</string>
}
Read more here: http://developer.android.com/reference/android/widget/TextView.html#attr_android:autoLink
It might be easier to create a button and inside your onClickListener() pull an email from maybe R.string.email.
Fro the Strings From strings.xml :
<string name="your_string"><![CDATA[ contact us at recipient#mail.com for more help.]]></string>
tvObject.setText(Html.fromHtml(getString(R.string.your_string)));
tvObject.setMovementMethod(LinkMovementMethod.getInstance());