3

I'm trying to use EditText with textPassword input type. I faced a situation in which all the characters entering in the field were selected by double tap in android version 5 and 4.4 while this feature didn't work on android version 6. Would you please help me to have this feature in all android versions?

This is my xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <EditText
        android:hint="Text Password Input Type"
        android:inputType="textPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

This is the result:

enter image description here

Nava
  • 368
  • 2
  • 11
  • I guess this problem is with simulator only & not on real device – VVB Aug 20 '17 at 06:38
  • @VVB This feature was checked on Samsung Note 4 with Lollipop and Nexus 5 with Marshmallow android version. The same result was occurred. – Nava Aug 20 '17 at 09:11

1 Answers1

0

THe general algorithm would be:

private long timeLastClicked;
private static final TIME_DOUBLE_CLICK_MS = 1000;
private EditText passwordField;  //should put the result of findViewById in here

...

myEditText.setOnClickListener(new OnClickListener() {
    public void onClick(View view) {
        long time = System.currentTimeMillis();
        if(time - timeLastClicked < TIME_DOUBLE_CLICK_MS) {
           passwordField.setSelection(0,passwordField.getText().length());
        }
        timeLastClicked = time;
});

What this does- it sets a click listener. When you see a click, you check if you already saw another click in the previous second. If so, you hilight the text. If not, you don't. Either way, you save the time of this click so you can compare it next time.

Gabe Sechan
  • 90,003
  • 9
  • 87
  • 127
  • Did you test this solution? didn't work for me. It seems the problem relates to setSelection() method. Because the algorithm is correct. – Nava Aug 26 '17 at 08:21