android-edittext

Allow only selected charcters based on regex in an EditText

萝らか妹 提交于 2019-12-17 19:02:09
问题 I want to allow users only to type certain characters based on the a regex in my android applications. How do I achieve it? 回答1: Used a TextWatcher as @Matt Ball suggested. @Override public void afterTextChanged(Editable s) { String text = s.toString(); int length = text.length(); if(length > 0 && !Pattern.matches(PATTERN, text)) { s.delete(length - 1, length); } } Edit Although the TextWatcher works, it would be cleaner to use an InputFilter . Check this example. 回答2: Try this: If the

EditText inside ListView will not stay focused [duplicate]

江枫思渺然 提交于 2019-12-17 18:46:37
问题 This question already has answers here : Focusable EditText inside ListView (12 answers) Closed 6 years ago . I have an EditText inside each row of a ListView . For some reason, when I tap the EditText, it briefly gains focus but then immediately loses it. I have tried these things: listView.setItemsCanFocus(true); editText.setFocusable(true); While the EditText is (briefly) focused, the Enter key says Next and the auto-correct bar is present. When it loses focus, the soft keyboard stays up,

EditText setOnFocusChangeListener on all EditTexts

痴心易碎 提交于 2019-12-17 18:37:54
问题 I have several EditText fields which I want to save to the SQLiteDatabase with setOnFocusChangeListener. Do I have to set an onFocusChangeListener on each one individually, or is there a catch-all of some sort? (getActivity().findViewByID because this is a fragment) final TextView txtName = (TextView)getActivity().findViewById(R.id.clientHeader); final TextView txtCompany = (TextView)getActivity().findViewById(R.id.txtContactCompany); final TextView txtPosition = (TextView)getActivity()

How to disable cursor positioning and text selection in an EditText? (Android)

馋奶兔 提交于 2019-12-17 18:28:43
问题 I'm searching for a way to prevent the user from moving the cursor position anywhere. The cursor should always stay at the end of the current EditText value. In addition to that the user should not be able to select anything in the EditText. Do you have any idea how to realize that in Android using an EditText? To clarify: the user should be able to insert text, but only at the end. 回答1: I had the same problem. This ended up working for me: public class CustomEditText extends EditText {

Android : How to set acceptable numbers and characters in EditText?

左心房为你撑大大i 提交于 2019-12-17 18:19:49
问题 I have to set acceptable characters "0123456789" and "semicolon" in the EditText. Below is the code I'm using. android:digits="0123456789;" android:inputType="number|text The problem with that implementation is in HTC phones, semicolon can't be entered but in Samsung and Sony Ericsson, semicolon can be entered. Another problem is when I entered semicolon in Samsung and Sony Ericsson, semicolon can't be deleted. Is there any missing property in the above code? Thanks in advance. 回答1: Android

Android EditText Max Length [duplicate]

半腔热情 提交于 2019-12-17 17:59:32
问题 This question already has answers here : What's the best way to limit text length of EditText in Android (20 answers) Closed last year . I set up a max length of text in an EditText field. <EditText android:id="@+id/courseDescriptionField" android:layout_width="fill_parent" android:layout_height="wrap_content" android:inputType="textMultiLine" android:lines="5" android:maxLength="@integer/max_course_description_limit" android:gravity="left|top" > </EditText> The problem for me however is,

Alternative of singleLine attribute (Deprecated) TextInputEditText

穿精又带淫゛_ 提交于 2019-12-17 17:47:14
问题 I recently used TextInputEditText and I got lint error that singleLine attribute is Deprecated <android.support.design.widget.TextInputEditText android:id="@+id/my_edit_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="@string/string_hint_dob" android:lines="5"/> </android.support.design.widget.TextInputLayout> Getting strike-through as below: Is there any alternative way for this? 回答1: The android:singleLine attribute has been deprecated since API

Cannot resolve symbol showsoftinput

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-17 17:14:56
问题 I'm trying to force the numeric keypad to show when my activity and EditText load. It seems there's a pretty straightforward answer given here and elsewhere: you say EditText yourEditText= (EditText) findViewById(R.id.yourEditText); InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT); Fine then. So I do this and I include the imports: import android.content.Context; import android.os

android : how to change the style of edit text?

不想你离开。 提交于 2019-12-17 16:27:56
问题 I'm trying to change the style of the EditText? Is it possible to achieve that? If so I'll appreciate being told about it, otherwise what alternative ways are available. 回答1: You can use the attribute style="@style/your_style" that is defined for any widget. To define your style you have to create a file called style.xml in the values folder (i.e. \res\values\styles.xml ) and use the following syntax: <style name="You.EditText.Style" parent="@android:style/Widget.EditText"> <item name=

How to restrict special characters from an Android EditText field?

与世无争的帅哥 提交于 2019-12-17 16:27:14
问题 How to restrict special characters from an Android EditText field? 回答1: Have you tried adding the android:digits="abcde.....0123456789" attribute? Although the android:digits specify that it is a numeric field, it does work for me to set it to accept letters as well, and special characters as well (tested on SDK-7). If this doesn't work then you'll have to implement KeyListener see: http://developer.android.com/reference/android/widget/TextView.html#setKeyListener(android.text.method