GoodieBag / Pinview

A pinview library for android. :sparkles:
MIT License
824 stars 115 forks source link

Two tiles are cleared when pressing DEL button on one tile #36

Open misaghE opened 5 years ago

misaghE commented 5 years ago

When I press DEL button to clear one tile (cursor is visible), the previous tile is also cleared. I debugged the code and found out that the problem maybe is in onKey() method:

 else if (currentTag > 0) {
                mDelPressed = true;
                if (editTextList.get(currentTag).length() == 0) {
                    //Takes it back one tile
                    editTextList.get(currentTag - 1).requestFocus();
                    //Clears the tile it just got to
                    editTextList.get(currentTag).setText("");
                } else {
                    //If it has some content clear it first
                    editTextList.get(currentTag).setText("");
                }
            }

I can't figure it out why calling setText("") when current tile has already length = 0. The previous tile has gained focus and so the currentFocus has been changed. Now calling setText("") on cached currentTag causes textChangeListener to get called and:

else if (charSequence.length() == 0) {
            int currentTag = getIndexOfCurrentFocus();
            mDelPressed = true;
            //For the last cell of the non password text fields. Clear the text without changing the focus.
            if (editTextList.get(currentTag).getText().length() > 0)
                editTextList.get(currentTag).setText("");
        }

Above lines clears the previous tile, because currentTag is now updated and previous tile is the currentFocus.

misaghE commented 5 years ago

In fact, I can't understand why we should pass the focus to previous tile when DEL button is pressed!! We've cleared a tile to insert a new value on it.

editTextList.get(currentTag - 1).requestFocus();