How to mask text in EditText when the view loses focus. - android

So if a user enters "1234" they will see "1234" in the EditText field. but when that field loses focus I want it to show "****"
So I've implemented a custom TransformationMethod that will only mask the entered text if the EditText field does not have focus.
when I enter the text "12345" it shows it as it should "12345" but when I click on a different field the numbers never get masked. I want to see "*****" but I still see the same "12345"
If I rotate the device though (force it to reload everything) it correctly shows "*****". And when I click on the EditText Field it correctly changes the masked text from "*****" to "12345" So it works when gaining focus but not when losing focus. I've tried implementing an OnFocusChangeListener but it seems to have no affect.
Is there any way I can force the EditText Field to redraw the text when it loses focus?
SetUp:
editText.setTransformationMethod(CustomPasswordTransformationMethod(numUnobfuscatedDigits))
editText.setOnFocusChangeListener { view, hasFocus ->
((EditText)view).invalidate()
((EditText)view).refreshDrawableState()
CustomPasswordTransformationMethod:
public class CustomPasswordTransformationMethod extends PasswordTransformationMethod {
private int unObfuscated = 1;
private boolean mIsFocused = false;
/**
* #param number the number of digits that will be unObfuscated at the end of the input string. Must be a positive integer or 0.
*/
public CustomPasswordTransformationMethod(int number) {
if (number < 0) {
Log.e(TAG, "Invalid parameter number =" + number + " number of un-obfuscated digits must be a positive integer or 0.");
unObfuscated = 0;
}
unObfuscated = number;
}
#Override
public CharSequence getTransformation(CharSequence source, View view) {
return new PasswordCharSequence(source);
}
#Override
public void onFocusChanged(View view, CharSequence sourceText,
boolean focused, int direction,
Rect previouslyFocusedRect) {
super.onFocusChanged(view,sourceText,focused, direction, previouslyFocusedRect);
mIsFocused = focused;
}
private class PasswordCharSequence implements CharSequence {
private CharSequence mSource;
public PasswordCharSequence(CharSequence source) {
mSource = source; // Store char sequence
}
public char charAt(int index) {
if(mIsFocused) return mSource.charAt(index);
else {
if (index < ((length()) - unObfuscated)) return '●';
return mSource.charAt(index);
}
}
public int length() {
return mSource.length(); // Return default
}
public CharSequence subSequence(int start, int end) {
return mSource.subSequence(start, end); // Return default
}
}
};

Try this and see if it does what you need.
editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean hasFocus) {
if(hasFocus){
editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
}
else{
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
}
}
});

Maybe you can try to keep it simple:
String password = "";
editText.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
editText.setText(password, TextView.BufferType.EDITABLE);
} else {
password = editText.getText().toString();
String ofuscated = "";
for (int i = 0; i < password.length(); i++){ ofuscated += "*"; }
editText.setText(ofuscated, TextView.BufferType.EDITABLE);
}
}
});

Related

multiline edittext where parts are not editable, like fill in the blanks

I need to have a view which contains textview and edittext.
Example:
Yay! you made it to ______ We should hang out! feel ____ to follow me.
Above "_____" could be of any length and it should feel like a paragraph in the end. Rest of the text given above is not changeable. Just like fill in the blanks.
From my perspective, a fill-in-the-blank widget should do the following:
Allow only certain identified portions of the text to be changed. The rest of the text is locked.
Not allow cursor movement into the locked text.
Flow from line to line like EditText.
Be generalized with variable placement of blanks.
Here is an implementation of such a widget based upon EditText. Editable spans are set up using a span (BlanksSpan) extended from StyleSpan. A blank span is identified by five underscores ("_____") in the text. Cursor movement is controlled in OnSelectionChanged() and various EditText callbacks. Changes to the text is monitor by a TextWatcher and adjustments to the displayed text are made there.
Here is the video of the widget in use:
FillInBlanksEditText.java
public class FillInBlanksEditText extends android.support.v7.widget.AppCompatEditText
implements View.OnFocusChangeListener, TextWatcher {
private int mLastSelStart;
private int mLastSelEnd;
private BlanksSpan mSpans[];
private Editable mUndoChange;
private BlanksSpan mWatcherSpan;
public FillInBlanksEditText(Context context) {
super(context);
init();
}
public FillInBlanksEditText(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public FillInBlanksEditText(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
mSpans = setSpans();
setOnFocusChangeListener(this);
}
#Override
public void onRestoreInstanceState(Parcelable state) {
mSpans = null;
super.onRestoreInstanceState(state);
Editable e = getEditableText();
mSpans = e.getSpans(0, e.length(), BlanksSpan.class);
}
#Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
addTextChangedListener(this);
if (findInSpan(getSelectionStart(), getSelectionEnd()) != null) {
mLastSelStart = getSelectionStart();
mLastSelEnd = getSelectionEnd();
} else if (findInSpan(mLastSelStart, mLastSelEnd) == null) {
setSelection(getEditableText().getSpanStart(mSpans[0]));
}
} else {
removeTextChangedListener(this);
}
}
#Override
protected void onSelectionChanged(int selStart, int selEnd) {
if (!isFocused() || mSpans == null ||
(getSelectionStart() == mLastSelStart && getSelectionEnd() == mLastSelEnd)) {
return;
}
// The selection must be completely within a Blankspan.
final BlanksSpan span = findInSpan(selStart, selEnd);
if (span == null) {
// Current selection is not within a Blankspan. Restore selection to prior location.
moveCursor(mLastSelStart);
} else if (selStart > getEditableText().getSpanStart(span) + span.getDataLength()) {
// Acceptable location for selection (within a Blankspan).
// Make sure that the cursor is at the end of the entered data. mLastSelStart = getEditableText().getSpanStart(span) + span.getDataLength();
mLastSelEnd = mLastSelStart;
moveCursor(mLastSelStart);
} else {
// Just capture the placement.
mLastSelStart = selStart;
mLastSelEnd = selEnd;
}
super.onSelectionChanged(mLastSelStart, mLastSelEnd);
}
// Safely move the cursor without directly invoking setSelection from onSelectionChange.
private void moveCursor(final int selStart) {
post(new Runnable() {
#Override
public void run() {
setSelection(selStart);
}
});
// Stop cursor form jumping on move.
getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
#Override
public boolean onPreDraw() {
getViewTreeObserver().removeOnPreDrawListener(this);
return false;
}
});
}
#Nullable
private BlanksSpan findInSpan(int selStart, int selEnd) {
for (BlanksSpan span : mSpans) {
if (selStart >= getEditableText().getSpanStart(span) &&
selEnd <= getEditableText().getSpanEnd(span)) {
return span;
}
}
return null;
}
// Set up a Blankspan to cover each occurrence of BLANKS_TOKEN.
private BlanksSpan[] setSpans() {
Editable e = getEditableText();
String s = e.toString();
int offset = 0;
int blanksOffset;
while ((blanksOffset = s.substring(offset).indexOf(BLANKS_TOKEN)) != -1) {
offset += blanksOffset;
e.setSpan(new BlanksSpan(Typeface.BOLD), offset, offset + BLANKS_TOKEN.length(),
Spanned.SPAN_INCLUSIVE_INCLUSIVE);
offset += BLANKS_TOKEN.length();
}
return e.getSpans(0, e.length(), BlanksSpan.class);
}
// Check change to make sure that it is acceptable to us.
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
mWatcherSpan = findInSpan(start, start + count);
if (mWatcherSpan == null) {
// Change outside of a Blankspan. Just put things back the way they were.
// Do this in afterTextChaanged. mUndoChange = Editable.Factory.getInstance().newEditable(s);
} else {
// Change is OK. Track data length.
mWatcherSpan.adjustDataLength(count, after);
}
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// Do nothing...
}
#Override
public void afterTextChanged(Editable s) {
if (mUndoChange == null) {
// The change is legal. Modify the contents of the span to the format we want.
CharSequence newContents = mWatcherSpan.getFormattedContent(s);
if (newContents != null) {
removeTextChangedListener(this);
int selection = getSelectionStart();
s.replace(s.getSpanStart(mWatcherSpan), s.getSpanEnd(mWatcherSpan), newContents);
setSelection(selection);
addTextChangedListener(this);
}
} else {
// Illegal change - put things back the way they were.
removeTextChangedListener(this);
setText(mUndoChange);
mUndoChange = null;
addTextChangedListener(this);
}
}
#SuppressWarnings("WeakerAccess")
public static class BlanksSpan extends StyleSpan {
private int mDataLength;
public BlanksSpan(int style) {
super(style);
}
#SuppressWarnings("unused")
public BlanksSpan(#NonNull Parcel src) {
super(src);
}
public void adjustDataLength(int count, int after) {
mDataLength += after - count;
}
#Nullable
public CharSequence getFormattedContent(Editable e) {
if (mDataLength == 0) {
return BLANKS_TOKEN;
}
int spanStart = e.getSpanStart(this);
return (e.getSpanEnd(this) - spanStart > mDataLength)
? e.subSequence(spanStart, spanStart + mDataLength)
: null;
}
public int getDataLength() {
return mDataLength;
}
}
#SuppressWarnings({"FieldCanBeLocal", "unused"})
private static final String TAG = "FillInBlanksEditText";
private static final String BLANKS_TOKEN = "_____";
}
activity_main.java
A sample layout.
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.example.fillintheblanks.FillInBlanksEditText
android:id="#+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="#android:color/transparent"
android:inputType="textMultiLine"
android:padding="16dp"
android:text="Yay! You made it to _____. We should hang out! Feel _____ to follow me."
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.example.fillintheblanks.FillInBlanksEditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:background="#android:color/transparent"
android:inputType="textMultiLine"
android:padding="16dp"
android:text="_____ says that it is time to _____. Are you _____?"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#id/editText" />
</android.support.constraint.ConstraintLayout>
A few things to note:
In extracted mode, cursor placement jumps around if a touch is made outside of a BlanksSpan. Things still work but misbehave a little.
The length of the blanks fields is fixed, but it can be made variable in length with some additional work.
The action mode in the control needs some work based upon requirements.
multiline edittext where parts are not editable, like fill in the blanks
You can use a TextWatcher() for this requirement
Try this he is the little work around for this
MainActivity
public class MainActivity extends AppCompatActivity {
EditText myEditText;
String startText = "I'm The First Part";
String lastText = "I'm The Last Part";
SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final SpannableStringBuilder firstStringBuilder = new SpannableStringBuilder(startText);
final SpannableStringBuilder lastStringBuilder = new SpannableStringBuilder(lastText);
StyleSpan firstStyleSpan = new StyleSpan(android.graphics.Typeface.BOLD);
firstStringBuilder.setSpan(firstStyleSpan, 0, firstStringBuilder.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make first 4 characters Bold
lastStringBuilder.setSpan(firstStyleSpan, 0, lastStringBuilder.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make first 4 characters Bold
myEditText = findViewById(R.id.myEditText);
spannableStringBuilder.append(firstStringBuilder);
spannableStringBuilder.append(" ");
spannableStringBuilder.append(lastStringBuilder);
myEditText.setText(spannableStringBuilder);
Selection.setSelection(myEditText.getText(), startText.length() + 1);
myEditText.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
#Override
public void afterTextChanged(Editable s) {
if (!s.toString().startsWith(firstStringBuilder.toString())
|| !s.toString().contains(lastText)) {
Log.e("StringBuilder_TAG", spannableStringBuilder.toString());
myEditText.setText(spannableStringBuilder);
Selection.setSelection(myEditText.getText(), myEditText.getText().length() - lastStringBuilder.length() - 1);
} else {
spannableStringBuilder.clear();
spannableStringBuilder.append(s.toString());
Log.e("My_TAG", spannableStringBuilder.toString());
}
}
});
}
}
layout.activity_main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:id="#+id/myEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:padding="5dp" />
</LinearLayout>
Here is the output video of above code https://www.youtube.com/watch?v=pfhUzLiFD6U
using above code you able to make not editble first and last parts of editext
Note
You can also use a TextDrawable
here are some links for that
How to put text in a drawable?
https://github.com/amulyakhare/TextDrawable
Set unchangeable some part of editText android
You can also create a custom EditText for this
Adding a prefix to an EditText
You can also use InputFilter
Solution one
Try using flexbox-layout - https://github.com/google/flexbox-layout.
Solution Two
Use textWatcher
Solution Three
Use html, css and javascript to design a simple webpage.
Use webview to load the html file.
Follow #Cheticamp 's answer, it works when you set a SpannableString in a setText() method.
Also you should override setText() method and set Spans to mSpans:
#Override
public void setText(CharSequence text, BufferType type) {
mSpans = Editable.Factory.getInstance().newEditable(text).getSpans(0, text.length(), BlanksSpan.class);
Log.d(TAG, "setText: " + mSpans.length);
super.setText(text, type);
}
if you don't set a SpannableString, Editable interface will get a simple String without Spans.
So if you call methods like:
Editable.getSpanStart(tag) returns -1;
Editable.getSpanEnd(tag) returns -1;
Editable.getSpans(start, end, Class) returns empty array

filter method is called twice android edittext on change keyboard language

I like to convert on the fly letters from cyrillic to latin. For example when user enter cyrillic letter I like to convert letter to latin. Here is the code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
test = (EditText) findViewById(R.id.test);
InputFilter filter = new InputFilter() {
TransliterationHelper tr = new TransliterationHelper();
public CharSequence filter(CharSequence source, int start, int end,
Spanned dest, int dstart, int dend) {
if (tr.isAlphaCyrilic(source.toString())) {
String convertedString = tr.returnLatinForCyrilic(source.toString());
return convertedString.toUpperCase();
} else if (tr.isAlpha(source.toString()))
return source.toString().toUpperCase();
else
return "";
return null;
}
};
test.setFilters(new InputFilter[]{filter});
}
Here is isAlphaCyrilic function:
public static boolean isAlphaCyrilic(String s) {
boolean isCyrilic = false;
for (char c : s.toCharArray()) {
if (Character.UnicodeBlock.of(c) == Character.UnicodeBlock.CYRILLIC) {
isCyrilic = true;
break;
}
}
return isCyrilic;
}
Here is the code for isAlpha
public static boolean isAlpha(String s) {
String pattern = "^[a-zA-Z ]*$";
if (s.matches(pattern)) {
return true;
}
return false;
}
The function returnLatinForCyrilic, return matched character for cyrillic letter:
public String returnLatinForCyrilic(String s) {
String strTranslated = cyrilicToLatinMap.get(s);
return strTranslated;
}
For example I enter only latin letters or cyrillic letters everything works ok, but when I enter cyrillic letter after latin (I changed keyboard language) method filter called again, and I don't like that.
Does someone has some idea?
I put android:inputType="textNoSuggestions"
so the method filter was not called twice.

Calling notifyDataSetChanged in my onFocusChangedListener causes focus to freak out in my ListView

I have a ListView which has multiple EditTexts per item. When I change an EditText on one item, I'd like it to affect the text on the next item. I'm using an onFocusChanged listener and I can successfully update the underlying data, but My actual focus is lost (and my cursor ends up in weird places). Please review my code and offer any insight. I've been banging my head about this for a while.
Note:
I am not recycling items using a holder, as this was giving me odd behavior and my performance is not suffering. Every time I've tried re-enabling the recycling, things get messier.
I have overriden hasStableIds to return true, but it doesn't seem to make any difference.
Assigning the Listener:
MyFocusChangeListener myFocusListener = new MyFocusChangeListener(myItem, position);
holder.et_min.setOnFocusChangeListener(myFocusListener);
Defining the Listener:
private class MyFocusChangeListener implements View.OnFocusChangeListener{
private EditText et;
private EditText curView;
private ScaleItem item;
private Integer pos;
public MyFocusChangeListener(ScaleItem item, Integer pos){
this.item = item;
this.pos = pos;
}
#Override
public void onFocusChange(View v, boolean hasFocus){
if(!hasFocus){
et = (EditText) v;
System.out.println("EditText lost focus on row: " + et.getText().toString() + " et id: " + et.getId());
if(pos < data.size()){
data.get(pos + 1).setMax(Double.valueOf(et.getText().toString()));
notifyDataSetChanged();
System.out.println("Updated dataset and called notifyDataSetChanged()");
}
} else {
et = (EditText) v;
if(et != null)
System.out.println("EditText just RECEIVED focus on row : " + et.getText().toString() + " et id: " + et.getId());
}
}
}
This is the console output I get, if I enter the activity, click field A, and then click field B.
Notice:
Each EditText (regardless of row) has the same ID (I think this is expected)
The only change I'm making is to the underlying data. In fact, I have the same issue if I change nothing but call notifyDataSetChanged.
The target field loses focus, I've no idea why.
TL;DR - Calling notifyDataSetChanged() in my onFocusChangedListener causes focus to freak out in my ListView.
See? The cursor is drunk.
If you focus a EditText in ListView get position value, after updating ListView redrawn and automatically it will select last position.
Step 1:
if (_Curserposition == position) {
holder.textViewStake.setFocusableInTouchMode(true);
//holder.textViewStake.clearFocus();
holder.textViewStake.requestFocus();
holder.textViewStake.setSelection(holder.textViewStake.getText().toString().length());
}
Step 2:
holder.textViewStake.setOnFocusChangeListener(new View.OnFocusChangeListener() {
#Override
public void onFocusChange(View v, boolean hasFocus) {
_Curserposition = position;
Log.d(">>>", "setOnFocusChangeListener" + _Curserposition);
/*
//showVirtualKeyboard(con_text, v);
// holder.textViewStake.requestFocus();
InputMethodManager imm = (InputMethodManager) activityContext.getSystemService(Context.INPUT_METHOD_SERVICE);
if (hasFocus) {
imm.showSoftInput(holder.textViewStake, InputMethodManager.SHOW_FORCED);
} else {
imm.hideSoftInputFromWindow(holder.textViewStake.getWindowToken(), 0);
}*/
}
});
Step 3:
holder.textViewStake.addTextChangedListener(new TextWatcher() {
#Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
betlist_view.setFocusable(false);
if (s.length() > 0) {
try {
if (Integer.parseInt(holder.textViewStake.getText().toString()) > 0) {
int _Stackamt = Integer.parseInt(holder.textViewStake.getText().toString());
int _picknumber = arrayDailyGameDrawList.get(position).getID();
//Log.d(">>>", "_picknumber" + position + "-" + arrayDailyGameDrawList.get(position).getBetNumberID() + "-" + Common.DrawId + "-" + _Stackamt + "-" + arrayDailyGameDrawList.get(position).getBetNumberID());
AddUpdateDailyGameNumberIntoList(
position,
2,
arrayDailyGameDrawList.get(position).getBetNumberID(),
Common.DrawId,
_Stackamt,
arrayDailyGameDrawList.get(position).getBetNumberID()
);
/* new Handler().postDelayed(new Runnable() {
#Override
public void run() {
}
}, 3000);*/
}
} catch (Exception e) {
}
} else {
holder.textViewStake.setText("0");
}
}
#Override
public void afterTextChanged(Editable s) {
}
});

How to exclude the digit number in the android reg expression

I am working to validate the name field, since there are so many country using different symbol as first, last name, I am going to validate the field by checking whether there is a number among the characters
private static final String NAME_REGEX = "\\d*";
public static boolean isName(EditText editText) {
return isValid(editText, NAME_REGEX) ? false : true; //Match digit pattern return true , meaning it is not a valid name
}
public static boolean isValid(EditText editText, String regex) {
String text = editText.getText().toString().trim();
return Pattern.matches(regex, text) ? true : false;
}
However, this pattern seems not working as I add some number it is still valid , what is the correct way of implement this? Thanks a lot
Just do this
private static final String NAME_REGEX = ".*\\d.";
I think this will work.
Do not use regx. InputFilter is proper way to do this kind of validation.
public class MainActivity extends Activity {
EditText edit;
InputFilter filter = new InputFilter() {
#Override
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
if (source.length() > 0) {
if (Character.isDigit(source.charAt(0)))
return "";
}
return null;
}
};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edit = (EditText) findViewById(R.id.edit);
edit.setFilters(new InputFilter[] { filter });
}
}
If you set the EditText to inputType to "textPersonName" there is no need for validation.
android:inputType="textPersonName"

Wrong input numbers in EditText filed when use hard keyboard

I have EditText field with android:numeric="decimal" and android:inputType="phone" for entering decimal numbers. I use input type phone because it is more easy to user enter numbers.
For any device with soft keyboard I haven't any problem but when I begin use hard keyboard when will print wrong numbers (for example when I use HTC Desire Z).
How to solve this problem?
P.S. I developed the "Simple Loan Calculator" for Android - it's opensource and freeware
Solved!
AndroidManifest.xml
<activity android:name=".MainActivity" android:label="#string/app_name" android:configChanges="keyboardHidden|orientation|keyboard" >
MainActivity.java
public void onCreate(Bundle savedInstanceState) {
....
setPriceInputFilter(amountEdit, interestEdit, fixedPaymentEdit, periodYearEdit, periodMonthEdit, downPaymentEdit, disposableCommissionEdit, monthlyCommissionEdit);
....
}
private void setPriceInputFilter(EditText ... fields){
PriceInputFilter filter = new PriceInputFilter();
for (EditText field: fields){
field.setFilters(new InputFilter[]{filter});
}
}
public void onConfigurationChanged(Configuration newConfig) {
if(newConfig.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_NO){
setInputType(InputType.TYPE_NULL, amountEdit, interestEdit, fixedPaymentEdit, periodYearEdit,
periodMonthEdit, downPaymentEdit, disposableCommissionEdit, monthlyCommissionEdit);
Toast.makeText(this, "HARD-keyboard", Toast.LENGTH_SHORT).show();
}else{
setInputType(InputType.TYPE_CLASS_PHONE, amountEdit, interestEdit, fixedPaymentEdit, periodYearEdit,
periodMonthEdit, downPaymentEdit, disposableCommissionEdit, monthlyCommissionEdit);
Toast.makeText(this, "SOFT-keyboard", Toast.LENGTH_SHORT).show();
}
super.onConfigurationChanged(newConfig);
}
private void setInputType(int type , EditText ... fields){
for (EditText field: fields){
field.setInputType(type);
}
}
PriceInputFilter.java
public class PriceInputFilter implements InputFilter {
public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
String checkedText = dest.toString() + source.toString();
String pattern = getPattern();
if (!Pattern.matches(pattern, checkedText)) {
return "";
}
return null;
}
private String getPattern() {
return "[0-9]+([.]{1}||[.]{1}[0-9]{1,2})?";
}
}

Categories

Resources