How to limit EditText length to 7 integers and 2 decimal places?

Try this under onCreate youreditText.setFilters(new InputFilter[] {new DecimalDigitsInputFilter(5,1)}); this anywhere in your program public class DecimalDigitsInputFilter implements InputFilter { Pattern mPattern; public DecimalDigitsInputFilter(int digitsBeforeZero,int digitsAfterZero) { mPattern=Pattern.compile(“[0-9]{0,” + (digitsBeforeZero-1) + “}+((\\.[0-9]{0,” + (digitsAfterZero-1) + “})?)||(\\.)?”); } @Override public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) { Matcher matcher=mPattern.matcher(dest); if(!matcher.matches()) … Read more

How to Get EditText maxLength setting in code

Only limited parameters have their getters, so I don’t think you can read it . So write length (Say 12) in values folder and use it in xml layout and arrayAdapter . Now its not hard-coded . 1)Create integer.xml in values * <?xml version=”1.0″ encoding=”utf-8″?> <resources> <item type=”integer” name=”max_length”>12</item> </resources> 2)In layout <TextView android:id=”@+id/tv” android:layout_width=”fill_parent” … Read more

How to Get EditText maxLength setting in code

Only limited parameters have their getters, so I don’t think you can read it . So write length (Say 12) in values folder and use it in xml layout and arrayAdapter . Now its not hard-coded . 1)Create integer.xml in values * <?xml version=”1.0″ encoding=”utf-8″?> <resources> <item type=”integer” name=”max_length”>12</item> </resources> 2)In layout <TextView android:id=”@+id/tv” android:layout_width=”fill_parent” … Read more

How to change the focus to next edit text in android?

Try TextWatcher instead of onKeyListener B’coz if want to edit your password, in that case TextWatcher will give you more method to dealt with.. Edited:- StringBuilder sb=new StringBuilder(); edtPasscode1.addTextChangedListener(new TextWatcher() { public void onTextChanged(CharSequence s, int start, int before, int count) { // TODO Auto-generated method stub if(sb.length()==0&edtPasscode1.length()==1) { sb.append(s); edtPasscode1.clearFocus(); edtPasscode2.requestFocus(); edtPasscode2.setCursorVisible(true); } } … Read more

Stop ScrollView from auto-scrolling to an EditText

After struggling with that problem for quite some time, I’ve found a solution that seems to work without being too ugly. First, make sure that whatever ViewGroup (directly) contains your EditText has descendantFocusability set to “Before Descendants,” focusable set to “true” and focusableInTouchMode set to “true.” This will not be the ScrollView itself, but the … Read more

how to validate a URL / website name in EditText in Android?

Short answer Use WEB_URL pattern in Patterns Class Patterns.WEB_URL.matcher(potentialUrl).matches() It will return True if URL is valid and false if URL is invalid. Long answer As of Android API level 8 there is a WEB_URL pattern. Quoting the source, it “match[es] most part of RFC 3987”. If you target a lower API level you could … Read more

set textCursorDrawable programmatically

Update 2019: There is no public API to set the cursor drawable. See https://stackoverflow.com/a/57555148/253468 for API available on 29 and above, before that conditionally you’ll need to use reflection as described below. Before API 29 you can set it programmatically by using reflection. The field mCursorDrawableRes hasn’t changed so this should work on all devices, … Read more