Can anyone tell me how to mask the substring in EditText
or how to change EditText
substring input to password type
public class Test extends AppCompatActivity {
EditText firstEditText;
EditText secondEditText;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test);
firstEditText = (EditText)findViewById(R.id.firstEditText);
secondEditText = (EditText)findViewById(R.id.secondEditText);
firstEditText.addTextChangedListener(new EditTextListener());
}
private class EditTextListener implements 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) {
secondEditText.setText(firstEditText.getText());
}
@Override
public void afterTextChanged(Editable s) {
}
}
}
if you implement with dialog edittext. use like this:. its same with use to other edittext.
dialog.getInputEditText().addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int start, int before, int count) {
}
@Override
public void onTextChanged(CharSequence charSequence, int start, int before, int count) {
if (start<2){
dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);
}else{
double size = Double.parseDouble(charSequence.toString());
if (size > 0.000001 && size < 0.999999){
dialog.getActionButton(DialogAction.POSITIVE).setEnabled(true);
}else{
ToastHelper.show(HistoryActivity.this, "Size must between 0.1 - 0.9");
dialog.getActionButton(DialogAction.POSITIVE).setEnabled(false);
}
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
Here is a visual supplement to the other answers. My fuller answer with the code and explanations is here.