Android Numeric EditText with multiple Lines - android

I have a numeric EditText and when I try to set multiple lines it doesn't work.
This is my code
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone" />
Java class
EditText editText = (EditText) view.findViewById(R.id.editText);
editText.setRawInputType(InputType.TYPE_CLASS_PHONE|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
Thanks.

Your flags are wrong. From the documentation:
TYPE_TEXT_FLAG_MULTI_LINE
Flag for TYPE_CLASS_TEXT: multiple lines of text can be entered into the field.
So TYPE_TEXT_FLAG_MULTI_LINE is compatible with TYPE_CLASS_TEXT but not TYPE_CLASS_PHONE.
I guess you just can't.

add these lines to your editext xml
android:minLines="2"
android:maxLines="3"
also, don't use android:singleLine="false" since it is deprecated

Related

inputType = "number|text" not working - Android

I am using inputType = "number|text" inside TextInputEditText when I focus on this, It lets me type number only, It allows to navigate to text keyboard but not letting me type text.
Here is the code snippet:
<android.support.design.widget.TextInputLayout
android:id="#+id/availableRoof"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/radio_groupPcOfInstltion"
android:visibility="visible">
<android.support.design.widget.TextInputEditText
android:id="#+id/avlbleRoofTextField"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Available Roof/Ground Area(sq.ft.)"
android:inputType="number|text"
android:text=""
android:textSize="13sp" />
</android.support.design.widget.TextInputLayout>
Please suggest a solution, so that I can type text and number both.
Just use input type text for getting the all possible options and textVisiblePassword for removing the suggestion and show number in one keyboard.
android:inputType="text"
OR
android:inputType="textVisiblePassword"
You need to set the inputType as text, so that you can easily enter text as well as numbers in the TextInputEditText.
Use: android:inputType="text"
Try adding these properties:
android:digits="abcdefghijklmnopqrstuvwxyz1234567890"
android:inputType="textVisiblePassword"

EditText with number keyboard(inputType) doesn't write numbers

I have an EditText with android:inputType="number" and doesn't write anything(numbers) when I press the numbers. The EditText is inside a dialog.
If I change number to numberSigned, the negative character it's OK, is possible to write, but not numbers.
When I change to android:inputType="phone", it doesn't work. But I change to "text" I can write numbers and text....
Same problem writting programatically setInputType(InputType.TYPE_CLASS_NUMBER);
and siscarded problem with mobile.
I don't know what is happening...
XML code:
<EditText
android:id="#+id/edTxtGenerarMicroPersonalizado"
android:paddingTop="3dp"
android:paddingLeft="5dp"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:digits="0123456789"
android:hint="Personalizado"
android:inputType="number"
android:visibility="gone" />
Edit Text declaration:
final EditText edTxtPersonalizado;
edTxtPersonalizado = (EditText) view.findViewById(R.id.edTxtGenerarMicroPersonalizado);
edTxtPersonalizado.setFilters(new InputFilter[]{new InputFilter.LengthFilter(4)});
edTxtPersonalizado.setVisibility(View.VISIBLE);
edTxtPersonalizado.requestFocus();
imm.showSoftInput(edTxtPersonalizado, InputMethodManager.SHOW_IMPLICIT); //Same problem without this
try
android:inputType="numberDecimal"
also, you have android:visibility="gone", so your EditText is not being shown

Edit Text without Autocorrect

I want an EditText without the autocorrection.
I have set the textNoSuggestions inputType, as shown:
<EditText
android:id="#+id/txtTarga"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Targa"
android:inputType="textNoSuggestions|textCapCharacters" >
The capitalize flag works, but it is still autocorrecting.
How can I disable it?
inputType textVisiblePassword will do the trick (most of the times, because as Commonsware pointed out, it stays a request and you'll might find yourself finding devices where it works, and devices where it doesn't work)
android:inputType="textNoSuggestions"
according to this, inputType attribute may or may not be supported by some devices .
However, this seems to work more often
android:inputType="textNoSuggestions|textVisiblePassword"
You could try by code, something like this:
EditText edittext = (EditText)findViewById(R.id.txtTarga);
edittext.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
In Xml
<EditText
android:id="#+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:hint="password"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:singleLine="true"
/>
In java source code
// casting done from EditText to TextView
TextView mPassword = (TextView) findViewById(R.id.password);
No idea why is this. But works fine.
textNoSuggestions does not work in every keyboard. The accepted answer inputType="textVisiblePassword" works but it removes emoji's from most keyboards.
I found that setting inputType="textUri" works and keeps the ability to add emojis.

Opening the numpad of the device [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Open a numeric keyboard without forcing the EditText to be numeric only
In my app i have an EditText field which accepts only integer values. so i thought it would be better to open the numpad automatically instead of the alphabetics when i click on this EditText.
How can i achieve this??
in your xml file when defining your EditText, you add your inputType as Number
android:inputType="number"
Using xml layout attributes
For this, you can use several xml attributes to your EditText xml definition (see android:inputType for available options)
Examples:
<EditText android:inputType="phone" ...
<EditText android:inputType="number" ...
<EditText android:inputType="numberSigned" ...
<EditText android:inputType="numberDecimal" ...
You can also both hint android to show digital keyboard and restrict input to acceptable characters with android:numeric
Examples:
<EditText android:numeric="integer" ...
<EditText android:numeric="signed" ...
<EditText android:numeric="decimal" ...
Programatically
Use EditText.setRawInputType(int) with constants such as TYPE_CLASS_NUMBER you will find in android:inputType
or
EditText editView = new EditText(this);
editView.setKeyListener(new NumberKeyListener())
EditText editView = new EditText(this);
editView.setKeyListener(new DigitsKeyListener());
Hope this help
See TextView Documentation as EditText extends from it :
http://developer.android.com/reference/android/R.styleable.html#AutoCompleteTextView_inputType

Android: How to set password property in an edit text?

I need to create a login form with 'username' 'password' fields and two buttons 'login' and 'cancel' in my android application.
I am using an alert dialog with edittext inside that.
This is the code I used to create password edittext..
final EditText Password = new EditText(this);
Password.setGravity(Gravity.CENTER);
Password.setHint("Password");
Password.setWidth(200);
Password.setTransformationMethod(new PasswordTransformationMethod());
login_alert.addView(Password);
My issue is that, plain text is shown instead of 'dots' when i open a softkeypad to edit the password. (It is shown as dots when not in softkeypad mode)
Can anyone suggest a solution?
Password.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
This one works for me.
But you have to look at Octavian Damiean's comment, he's right.
This is deprecated
In xml of EditText iclude this attribute: android:password="true"
Edit
android:inputType="textPassword"
Here's a new way of putting dots in password
<EditText
android:id="#+id/loginPassword"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:hint="#string/pwprompt" /
add android:inputType = "textPassword"
You need to use PasswordTransformationMethod.getInstance() instead of new PasswordTransformationMethod().
The only way that worked for me using code (not XML) is this one:
etPassword.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
etPassword.setTransformationMethod(PasswordTransformationMethod.getInstance());
See this link
text view android:password
This applies for EditText as well, as it is a known direct subclass of TextView.
I found when doing this that in order to set the gravity to center, and still have your password hint show when using inputType, the android:gravity="Center" must be at the end of your XML line.
<EditText android:textColor="#000000" android:id="#+id/editText2"
android:layout_width="fill_parent" android:hint="Password"
android:background="#drawable/rounded_corner"
android:layout_height="fill_parent"
android:nextFocusDown="#+id/imageButton1"
android:nextFocusRight="#+id/imageButton1"
android:nextFocusLeft="#+id/editText1"
android:nextFocusUp="#+id/editText1"
android:inputType="textVisiblePassword"
android:textColorHint="#999999"
android:textSize="16dp"
android:gravity="center">
</EditText>
To set password enabled in EditText, We will have to set an "inputType" attribute in xml file.If we are using only EditText then we will have set input type in EditText as given in below code.
<EditText
android:id="#+id/password_Edit"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="password"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:maxLength="100"
android:nextFocusDown="#+id/next"
android:layout_width="match_parent"
android:layout_height="match_parent" />
Password enable attribute is
android:inputType="textPassword"
But if we are implementing Password EditText with Material Design (With Design support library) then we will have write code as given bellow.
<android.support.design.widget.TextInputLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/txtInput_currentPassword"
android:layout_width="match_parent"
app:passwordToggleEnabled="false"
android:layout_height="wrap_content">
<EditText
android:id="#+id/password_Edit"
android:focusable="true"
android:focusableInTouchMode="true"
android:hint="#string/hint_currentpassword"
android:imeOptions="actionNext"
android:inputType="textPassword"
android:maxLength="100"
android:nextFocusDown="#+id/next"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</android.support.design.widget.TextInputLayout>
#Note: - In Android SDK 24 and above, "passwordToggleEnabled" is by default true. So if we have the customs handling of show/hide feature in the password EditText then we will have to set it false in code as given above in .
app:passwordToggleEnabled="true"
To add above line, we will have to add below line in root layout.
xmlns:app="http://schemas.android.com/apk/res-auto"
My search for a similar solution for Visual Studio 2015/Xamarin lead me to this thread. While setting the EditText.InputType to Android.Text.InputTypes.TextVariationVisiblePassword properly hid the password during user entry, it did not 'hide' the password if it was visible before the EditText Layout was rendered (before the user submitted their password entry). In order to hide a visible password after the user submits their password and the EditText Layout is rendered, I used EditText.TransformationMethod = PasswordTransformationMethod.Instance as suggested by LuxuryMode.

Categories

Resources