android-edittext

How to clear the selection in an EditText?

旧城冷巷雨未停 提交于 2020-01-01 09:32:47
问题 How do you programmatically remove the selection from an EditText ? I've tried: myEditText.setSelection(selectionEnd); but that just creates a selection of 0 length at the end of the current selection. I've also tried Selection.removeSelection(mySpannable) , and it just puts an empty selection at the beginning of the text. 回答1: Calling myEditText.clearFocus(); . I think that's what you need 回答2: To move selection to top: edit_text.setSelection(0); To move selection to bottom: edit_text

android: the first digit in the edit text can not be zero

别等时光非礼了梦想. 提交于 2020-01-01 09:29:09
问题 I have an EditText element with a number input type. I don't want users to be able to enter 0 as the first digit. Can I enforce this using XML? Here is what I have currently: <EditText android:id="@+id/main_edt_loan" android:layout_width="fill_parent" android:layout_height="40dip" android:background="@drawable/sample_editbox" android:ems="10" android:layout_margin="10dip" android:inputType="number" android:hint="" android:ellipsize="start" android:maxLines="1" android:imeOptions="actionNext"

How to set color of UnderlineSpan?

你说的曾经没有我的故事 提交于 2020-01-01 09:00:10
问题 This question is a follow up to my last question: How to highlight text like Android spell-checker? I'm using an UnderlineSpan to underline text in an EditText but I need the underline to be IN COLOR like this screen shot of the spelling checker: 回答1: Unfortunately, you can't do this solely with a Span -- there are no public methods to do what you ask. There is a method to set the underline color in TextPaint independent of the text color (you can see it in the source code for SuggestionSpan)

android:errorMessageBackground getting no resource found error in styles.xml

ぐ巨炮叔叔 提交于 2020-01-01 08:48:49
问题 i was working on EditText validations and using ' setError ' to show error messages. My primary motto is to change the error popup as par my application design. I used the "android:errorMessageBackground" in styles but unfortunately i am getting **No Resource found error** . Used Base API: 2.2 (Even tried with 4.0.3 also) not sure what we need to do ? 回答1: This seems to be a known issue: https://code.google.com/p/android/issues/detail?id=55879 来源: https://stackoverflow.com/questions/13874197

Prevent drag drop of custom mimetype to EditText

空扰寡人 提交于 2020-01-01 08:36:09
问题 I have a custom mime type which I am intending to use to drag and drop application objects within the app. This seems to be working but I'm finding that the EditText fields are also accepting the drop action. I don't want this to happen. First, I've defined the custome mime type like this: public static final String MIME_TYPE_MYNODE = "com.example.mockup/mynode"; Then, in the onTouch handler for the source object I have: @Override //------------------------------------------------------------

Android: How to open keyboard for editing EditText when click button?

非 Y 不嫁゛ 提交于 2020-01-01 05:22:30
问题 my case is: I have one EditText field that is with disabled focus. Beside EditText field I has two buttons for Input methods. So I want when click first button: to open soft keybord and edit text in EditText field. I try many ways with: InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT); and doesn't work for me. Only way to open soft keyboard is: toggleSoftInput(InputMethodManager.SHOW

EditText now showing under ListView

為{幸葍}努か 提交于 2020-01-01 03:46:04
问题 Here is my layout: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <ListView android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@android:id/list" /> <EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:id="@+id/search" android:hint="Filter results" /> What is

Saving data in edittext when hitting Back button

こ雲淡風輕ζ 提交于 2020-01-01 03:38:08
问题 So on activity 1 I click a button that takes me to activity 2. In activity 2 I enter some data into an EditText. When I hit the back button on the phone it takes me to activity 1 which is correct but if I hit the activity 1 button again any text that I entered into the EditText is gone. I am sure this is because I am starting a new Intent every time I hit my button and I think I need to be using Flags but I am not certain. Below is my basic MainActivity1 and MainActivity2 without the code I

How to format the input of EditText when typing with thousands separators (,) in Android?

泪湿孤枕 提交于 2019-12-31 22:23:10
问题 I've an edittext , it only gets numeric without decimal numbers. android:inputType="number" I want to separate thousands while I'm typing . For example 25,000 . I know I should use TextWatcher and I've used this code but I couldn't make it work : @Override public void afterTextChanged(Editable viewss) { String s = null; try { // The comma in the format specifier does the trick s = String.format("%,d", Long.parseLong(viewss.toString())); } catch (NumberFormatException e) { } } Could you help

In Android - How can I register only long clicks using a ClickableSpan

白昼怎懂夜的黑 提交于 2019-12-31 21:42:13
问题 I would like to register clicks on a text wrapped in a ClickableSpan only if they are clicked for over say 1 second. Is there any way to do this? If not, capturing a double click would also be fine. It would be great if the onClick method captured an event that had some meta data about the click - then I could say ignore if the click length was short. Any advice? Thanks, Victor 回答1: In case anyone needs it, I found it on this place package leeon.mobile.BBSBrowser; import android.text.Layout;