Only Text in EditText on Android? - 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

Related

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

Android emulator : insert negative number?

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));

Add a title or description to an EditText

If you open an app like gmail, and you compose a new email in the To and Subject lines, it says To and Subject in the respective EditText's. How do you add a title like that to an EditText? Are those custom views? Or is it possible to do that with the default widget?
Thanks.
It is called a hint.
Set your hint programatically or use it as xml attribute.
I think the attribute hint is what you are looking for.
Here is some sample code:
<EditText android:hint="Write Caption" />

How do I make android keyboard display a '.com' button

I have an EditText. My imeOptions attribute for the EditText is actionGo. What do I have to do to make it display a '.com' key?
This is controlled by android:inputType i think.
Try textUri.
For this you have to provide your edittext with input type attribute to do this.
android:inputType="textEmailAddress"
Using the EditText attribute android:inputType="textWebEditText" should give you the .com and applicable web buttons

EditText not wrapping its content

I am trying to create an EditText which toggles its state between read only and write mode.
My XML is as below:
<EditText xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/textArea"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="4"
android:inputType="textMultiLine">
</EditText>
In my code i do the following :
textArea = (EditText) convertView.findViewById(com.pravaa.mobile.R.id.textArea);
//isEditable decides if the EditText is editable or not
if(!isEditable){
textArea.setInputType(InputType.TYPE_NULL);
}
//the view is added to a linear layout.
addView(textArea);
My issue is that the text does not get wrapped. Am i missing out on something? Kindly help me with this. I have also attached an image of my output.
The text set in the view is "12345678901234567 90123456789012345678901234567890 Nationwide Campaign New"
I was able to solve this issue by removing
android:inputType="textMultiLine"
To achieve the non-editable feature I used
setFocusable(false);
I guess that by calling this ...
textArea.setInputType(InputType.TYPE_NULL);
you override the flag InputType.TYPE_TEXT_FLAG_MULTI_LINE. Try calling this instead...
textArea.setInputType(InputType.TYPE_NULL|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
This line will make the text multi-line and will wrap the text
textArea.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
You'd probably also want to call setLines(n) to set the height of the textArea.
Try to replace:
editText.setInputType(InputType.TYPE_NULL);
with:
editText.setRawInputType(InputType.TYPE_NULL);
I would say that by using textArea.setInputType(InputType.TYPE_NULL); you remove the textMultiLine from your xml.
Just set textMultiLine isn't enough. Try this:
textArea.setHorizontallyScrolling(false);
textArea.setEllipsize(null);
textArea.setInputType(InputType.TYPE_NULL|InputType.TYPE_TEXT_FLAG_MULTI_LINE);
What me helped was:
edtText.setInputType(InputType.TYPE_NULL);
edtText.setSingleLine(false);
It seems that the setSingleline Attribute in the XML file is ignored.

Categories

Resources