android-edittext

Android: How to TOTALLY disable copy and paste function in Edittext

非 Y 不嫁゛ 提交于 2019-12-17 20:49:46
问题 I am quite new to Android developing area and recently I hv encountered a tough problem. I was trying to make a Edittext which should NOT ALLOW user to copy content from or paste content to it. I hv googled a lot and find there seems to be 2 popular ways of doing so: 1st way, to set it in the layout file: android:longClickable="false" 2nd way, to programmatically set it: myEdittext.setCustomSelectionActionModeCallback(new ActionMode.Callback() { public boolean onPrepareActionMode(ActionMode

How to set Edittext view allow only two numeric values and two decimal values like ##.##

纵饮孤独 提交于 2019-12-17 20:42:00
问题 I need to set validation for a edittext view should allow two numeric values and two decimal values. example: 22.32 Please let me know how to do this validation Thanks in advance 回答1: boolean isValid=<EditText Variable>.getText().toString().matches("\\d{2}\\.\\d{2}"); Put this method in a onClickListener and I guess you will be good to go. 回答2: Try this out. I suck at regex so it may not be the best, but give it a try. EditText text = new EditText(this); InputFilter[] filters = new

Unable to use drawable in EditText inside TextInputLayout

只谈情不闲聊 提交于 2019-12-17 20:28:24
问题 I recently upgraded Android Design library from 24.2.1 to 25.0.0. After this the "drawableX" feature in EditText doesn't work. EDIT 01.11: I learned that setting drawable in xml works if you use android:drawableStart instead of android:drawableLeft. But setting setting drawables programatically does not work. I use this to make a "Clear"-button to empty the EditText. But this feature is broken now. I would appreciate any work-arounds or knowledge about if this is intentional from Google or a

Android fixed width EditText within TableRow

随声附和 提交于 2019-12-17 20:25:25
问题 I'm completely stuck trying to get fixed width EditText widgets in a TableRow. I am attempting to place two EditText side by side with equal width (about 20dip) but no matter which property I try and set the first EditText is way to long and apparently cannot be resized. Many thanks: <TableRow android:layout_height="wrap_content" android:baselineAligned="false" android:id="@+id/tableRow3" android:gravity="center" android:stretchColumns="1" android:layout_width="match_parent"> <TextView

EditText in Android doesn't show text when typing while using the on-screen keyboard

戏子无情 提交于 2019-12-17 20:25:07
问题 I have an activity consisting of 3 EditText fields (amongst other things like TextViews and a few buttons). I also have an AutoCompleteTextView with a list of String's using an ArrayAdapter. Whenever I test the app in an emulator, I can type when the keyboard is up but it doesn't show the text (it still gives predictions) and the text only appears in the EditText box once the keyboard is closed down. This happens when I test it on my phone, too. However, it works and shows up as you type on

Android: EditText Validation with TextWatcher and .setError()

邮差的信 提交于 2019-12-17 19:55:44
问题 i have implemented a simple validation for an TextEdit, using this code: title = (EditText) findViewById(R.id.title); title.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { if (title.getText().length() < 1) { title.setError( "Title is required" ); } else { title.setError(null); } } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // TODO Auto-generated method stub } @Override public void onTextChanged

How to parse a double from EditText to TextView? (Android)

落爺英雄遲暮 提交于 2019-12-17 19:44:59
问题 I'm realy beginning to learn Java. When I run this code everything works fine till I leave my EditText boxes in the from empty and hit the run button. Then I get: ERROR/AndroidRuntime(866): FATAL EXCEPTION: main ERROR/AndroidRuntime(866): java.lang.NumberFormatException: ERROR/AndroidRuntime(866): at org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:267) I guess when I try to parse a Double from string it doesn't get any value and creates an error. I was

How do I get MultiAutoCompleteTextView tokenizer similar to Facebook app?

爷,独闯天下 提交于 2019-12-17 19:39:54
问题 I am creating an application which has a 'To' field just like in Facebook app's "New Message" feature. After selecting an item from the drop down list, I create an imagespan and add it to the MultiAutoCompleteTextView . I have used SpaceTokenizer for this view . The problem is when I click on backspace, the cursor first moves to the empty space (i.e., space Tokenizer ) and then when I click on the backspace again, the whole word gets deleted....I want to delete the whole word on my first

EditText with not-editable/not-cancellable suffix

吃可爱长大的小学妹 提交于 2019-12-17 19:21:44
问题 i created a layout for one of my activities in which users can insert a value in some EditText widget. I need that some of these EditText must have a suffix (like cm, mm and so on) that has to be not editable. After the user has inserted the value i will parse the content of these EditText avoiding the suffix so i will handle the only input without the suffix. How to do that? I have already searched and searched here on SO but nothing helped me. I found answers like this one https:/

Allow only selected charcters based on regex in an EditText

断了今生、忘了曾经 提交于 2019-12-17 19:04:03
问题 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