Android emulator : insert negative number? - android

I suppose it must be easy but how do I insert a negative number in an EditText?
I am running the emulator on a Mac.
Thank you.

Just press '-' before you enter the number?
If that's not possible, there is probably something wrong with the inputType of the editText.
For example, android:inputType="numberDecimal" doesn't allow negative numbers. In that case you should add: android:inputType="numberDecimal|numberSigned".

In resource file .axml, EditBox change type
android:inputType="numberDecimal"
to
android:inputType="numberDecimal|numberSigned"
It works for me

EditText yourEditText = (EditText)findViewById(R.id.yourEditText);
yourEditText.setText("whatever");

editText.setText(String.valueOf(-1));

Related

EditText with automatic return

I have an EditText in my Android app. When I write something on it I don´t have the enter on my Keyboard and when the cursor goes to the final of the line doesn´t jump to the line below automatically. Which are the properties to change this? Thank you so much.
I answer my own question, it works
edittxt.setInputType(EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
edittxt.setMinLines(minLines);
edittxt.setGravity(Gravity.TOP);
edittxt.setVerticalScrollBarEnabled(true);
edittxt.setSingleLine(false);
Write these two lines in edit text xml
android:singleLine="false"
android:inputType="textMultiLine|textAutoCorrect"

Restrict Input Type EditText Android

I need to restrict input type of EditText in Android such a way that user can enter only digits from 0-9 and user can enter one comma(,) in entire input.
Example: 455,67
try using following code, Hope it works :)
android:inputType="text"
android:digits="1234567890,"
A custom filter extends InputFilter could be wrote. You can look over the link.
http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/text/InputFilter.java
writing this
android:inputType="number"
in XML attributes of edit text will do that for you

How to enter a "Negative Decimal Number" in EditText?

I am making a calculator and I want to make sure that user is able to enter a "Negative Decimal Number" I see the option in the xml file separately for example in order to put the Decimal Number, the EditText's inputType must be numberDecimal and for negative number the inputType must be "numberSigned" but I need both. If I choose inputType as "text" then user is able to enter anything which throws an exception if it's not a number. I am not sure how to fix that either.
You can use both with the "|" operator. Just specify "numberSigned|numberDecimal".
Add this in the layout of the EditText:
android:digits="0123456789-."
You can specify more there, for example if you want the user to input sin() functions.
As #a11n says, you can use the pipe operator to specify both:
<EditText
...
android:inputType="numberSigned|numberDecimal"
... />
Valid numbers: positive and negative decimal and whole numbers.
Some phones have the decimal and negative in the same button and makes it unable to do negatives. I figured out a way you could separate the buttons by simply adding:
android:inputType="numberSigned|numberDecimal|textPersonName"
android:digits="0123456789.-"
That way you still have the number keyboard layout but the negative and decimal buttons will be separate and you cannot use any other digit that messes up the app.

Only Text in EditText on Android?

I want to only text (input) in edittext in App Android.!
example: Only type "Text: A-> Z", Not allow number or special character.?
Please give me idea, how should it be done?
Thank very much.!
Try this way,
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
android:inputType="text"
For more info, you may check http://developer.android.com/reference/android/widget/TextView.html#attr_android:digits
I think you can do this by the following attribute in ur xml file.
android:inputType
for more on this see this link:
http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType
i think you should set it like this:
android:inputType="text"
or try this:
http://www.anddev.org/view-layout-resource-problems-f27/how-to-create-edittext-allow-only-alphabets-capital-and-smal-t12236.html

Android virtual keyboard turn on caps lock

I have an edit text field. When the user clicks on it by default it shows small letters on the virtual keyboard.
I want by default to display first letter caps and rest of them small on the keyboard.
How can this be done?
android:capitalize is deprecated. So please use: android:inputType
android:inputType="textCapSentences"
Try adding android:capitalize="sentences" to the definition of the EditText in your Layout file. This should capitalize the first character of the sentence. If you want to begin each word with a capital letter use words.
More about this can be found in the API.
In order to captialize every character of EditText
use these property.
android:capitalize="characters"
I used below attribute with textCapCharacters value in my EditText to turn on caps lock on the virtual keypad and it worked.
android:inputType="textCapCharacters"
To capitalize all characters of Keyboard use this in your edittext in xml:
android:inputType="textCapCharacters"
To capitalize of the first character of every sentence use this :
android:inputType="textCapSentences"

Categories

Resources