Decimal separator comma (‘,’) with numberDecimal inputType in EditText

A workaround (until Google fix this bug) is to use an EditText with android:inputType=”numberDecimal” and android:digits=”0123456789.,”. Then add a TextChangedListener to the EditText with the following afterTextChanged: public void afterTextChanged(Editable s) { double doubleValue = 0; if (s != null) { try { doubleValue = Double.parseDouble(s.toString().replace(‘,’, ‘.’)); } catch (NumberFormatException e) { //Error } } … Read more

Setting onClickListener for the Drawable right of an EditText [duplicate]

Simple Solution, use methods that Android has already given, rather than reinventing wheeeeeeeeeel 🙂 editComment.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { final int DRAWABLE_LEFT = 0; final int DRAWABLE_TOP = 1; final int DRAWABLE_RIGHT = 2; final int DRAWABLE_BOTTOM = 3; if(event.getAction() == MotionEvent.ACTION_UP) { if(event.getRawX() >= (editComment.getRight() – editComment.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) { … Read more

Get Value of a Edit Text field

By using getText(): Button mButton; EditText mEdit; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mButton = (Button)findViewById(R.id.button); mEdit = (EditText)findViewById(R.id.edittext); mButton.setOnClickListener( new View.OnClickListener() { public void onClick(View view) { Log.v(“EditText”, mEdit.getText().toString()); } }); }

Move to another EditText when Soft Keyboard Next is clicked on Android

Focus Handling Focus movement is based on an algorithm which finds the nearest neighbor in a given direction. In rare cases, the default algorithm may not match the intended behavior of the developer. Change default behaviour of directional navigation by using following XML attributes: android:nextFocusDown=”@+id/..” android:nextFocusLeft=”@+id/..” android:nextFocusRight=”@+id/..” android:nextFocusUp=”@+id/..” Besides directional navigation you can use tab … Read more

Limit Decimal Places in Android EditText

More elegant way would be using a regular expression ( regex ) as follows: 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); … Read more

Saving EditText content in RecyclerView

The major problem with your solution is allocating and assigning TextWatcher in onBindViewHolder which is an expensive operation that will introduce lags during fast scrolls and it also seems to interfere with determining what position to update in mAdapter. Making all operations in onCreateViewHolder is a more preferable option. Here is the complete tested working … Read more

Outlined Edit Text from Material Design

Read Outline Box . Outline text fields have a stroked border and are less emphasized. To use an outline text field, apply the following style to your TextInputLayout: style=”@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox” Dependencies implementation ‘com.android.support:design:28.0.0-alpha1’ XML <android.support.design.widget.TextInputLayout android:id=”@+id/name_text_input” style=”@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox” android:layout_width=”match_parent” android:layout_height=”wrap_content” > <android.support.design.widget.TextInputEditText android:id=”@+id/name_edit_text” android:layout_width=”match_parent” android:layout_height=”wrap_content” android:hint=”@string/label_name” /> </android.support.design.widget.TextInputLayout> DEMO FYI Legacy support ended in Android 28 . … Read more

Android: How can I validate EditText input?

Why don’t you use TextWatcher ? Since you have a number of EditText boxes to be validated, I think the following shall suit you : Your activity implements android.text.TextWatcher interface You add TextChanged listeners to you EditText boxes txt1.addTextChangedListener(this); txt2.addTextChangedListener(this); txt3.addTextChangedListener(this); Of the overridden methods, you could use the afterTextChanged(Editable s) method as follows @Override … Read more