edit text in android - android

hi
i want to restrict the special characters (!,#,#,$ etc.) from entering in to Edit Text field in android. how to do this please any body help..
thnx.

You need to use input filter and set it on Edit Text with setFilters method

You need to look at the reference. EditTest inherits from TextView:
http://developer.android.com/reference/android/widget/TextView.html
There you can add an TextChangedListener:
addTextChangedListener(TextWatcher watcher)
Then you test for your special characters and remove them if they are found

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

how to put hint to edittext

I have two edittext input box. First one is for username and the second one is for password. I want put hint on the inputbox. I have wrote hint with settex() method. In addition, I have wrote
in onclick(view v)
caseR.id.editText_1:
text1.setText("");
break;
in oncreate
text1 = findViewById(R.id.editText_1);
text1.setText("username");
whenever I have click on the input box, hint should dissappear. But, hint is not dissappeared. Now, is the way I am doing wrong? Or I have missed something?
Use
text1.setHint("MyHintString");
instead. setHint() provides the hint that disappears when the user types something. You can also use a String resource ID or an xml based approach, but in your case, using the String method will suffice.
Only use setText() when you want to put text in the EditText that the user can modify.
the correct way to do this is to use setHint(int resource) with a string resource containing your hint string.
so your onCreate should have : text1.setHint(R.String.yourhint);
and your res->values->strings.xml file should contain
<string name="yourhint">This Hint Will Disappear</string>
Use setHint(String hint) to specify the hint in an EditText.
text1.setHint("This is the hint...");
Or, in your XML layout file, you can use the attribute android:hint="This is the Hint" for the corresponding EditText.
You can use editTextExample.setHint("example") to achieve what you want.
OR, in XML, add this to your EditText: android:hint="example"
If you want to set it in xml file of the activity you can do it like this too.
in your xml file android:hint="#string/yourhint"
and your res->values->strings.xml file should contain
<string name="yourhint">This Hint Will Disappear</string>

How to set multiline,firstletter caps and disable suggestions on edittext

I have an edittext for reply to email. i want to give three properties for edittext like Multiline, First character caps and disable word suggestions.
I gave like this in xml...
android:inputType="textCapSentences|textVisiblePassword"
I tried in code also... etMessage.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE|InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
I am not able to give multiline....how can i achieve this
thanks
I found solution for this problem
Just set the following parameters in xml file..
android:inputType="textCapSentences|textVisiblePassword"
These are for setting first letter of sentence to caps and disable suggestions
and write following code in ur Activity
edittext.setSingleLine(false);
Try setting android:inputType="textMultiLine|textCapSentences|textVisiblePassword". What might be happening is that it is multiline but only one line is currently shown, in which you could say android:minLines="5" or so.

android EditText inputType for StreetNumber field

I'm trying to choose correct inputType in my adress dialog streetNumber field.
I want to show numeric keyboard first, but then let user also to input alphabetic characters
for some very special cases. Closer to this is inputType datetime,
but this doesn't allow to enter alphabetic characters. So how to set my streetNumber field correctly?
Use android:inputType="textPostalAddress"
The EditText inherits from TextView and shares its input type attributes with it. They can be found here in the official documentation.
Maybe the input type textPostalAddress would be suitable for your need. If not, plenty of other types are available. The XML attribute that allows setting this type is android:inputType="the type you have chosen".
See if this can help you
myEditText.setRawInputType(Configuration.KEYBOARD_QWERTY)

Access text of Multiline TextView in Android

I want to access text of particular line in a multi-line TextView. Any suggestions on how I could do this?
Fetch the Layout (android.text.Layout) of the TextView by calling mTextView.getLayout(); There you can for instance use the getLineStart or getLineEnd methods to get the offset of the text. That combined with getText and used using normal String operations should probably be enough for u!
By default, text view is multi line. Set the text with new line characters for ex. "First line \nSecond line".
Another option is listed here : https://stackoverflow.com/questions/2610280/how-to-get-multi-line-text-on-a-button-in-android

Categories

Resources