Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong selection when another TextWatcher was added #19

Open
Parmakli opened this issue Mar 2, 2018 · 5 comments
Open

Wrong selection when another TextWatcher was added #19

Parmakli opened this issue Mar 2, 2018 · 5 comments

Comments

@Parmakli
Copy link

Parmakli commented Mar 2, 2018

Thanx for the library!
For example I have two maskedEditTexts one below other and for the first one I just add another empty TextWatcher

maskedEditText.addTextChangedListener(object :TextWatcher{
            override fun afterTextChanged(s: Editable?) {
            }

            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }
        })

I receive such behaviour:
maskededittext
Both have mask and hint +7 ### ###-##-##
Workaround is to set empty string as text programmatically before any user action.

@Mixser
Copy link
Contributor

Mixser commented Mar 16, 2018

Hello, I can't reproduce this behavior, can you send a whole code example?

@Parmakli
Copy link
Author

Parmakli commented Mar 17, 2018

Of course, here is layout activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.igor.myapplication.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!" />

    <com.vicmikhailau.maskededittext.MaskedEditText
        android:id="@+id/maskedEditText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        app:mask="+7 ### ###-##-##"
        android:hint="+7 ### ###-##-##"
        android:inputType="phone"/>

    <com.vicmikhailau.maskededittext.MaskedEditText
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        app:mask="+7 ### ###-##-##"
        android:hint="+7 ### ###-##-##"
        android:inputType="phone"
        android:layout_below="@+id/maskedEditText"
        android:layout_centerHorizontal="true"
        android:layout_width="wrap_content"/>
</RelativeLayout>

And here is MainActivity

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        title = "MaskedEditText"

        maskedEditText.addTextChangedListener(object :TextWatcher{
            override fun afterTextChanged(s: Editable?) {
            }

            override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
            }

            override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
            }
        })
    }
}

And that's from gradle

compile ("com.vicmikhailau:MaskedEditText:2.0.4"){
        exclude group: 'com.android.support'
}

@mkruglikov
Copy link

mkruglikov commented Oct 1, 2018

I have the same problem even without TextWatcher

<android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="@dimen/filter_fragment_margin_horizontal"
            android:layout_marginLeft="@dimen/filter_fragment_margin_horizontal"
            android:layout_marginRight="@dimen/filter_fragment_margin_horizontal"
            android:layout_marginStart="@dimen/filter_fragment_margin_horizontal"
            android:layout_marginTop="@dimen/filter_fragment_margin_top"
            android:textColorHint="@color/filter_text_passive_color">

            <com.vicmikhailau.maskededittext.MaskedEditText
                        android:id="@+id/phone_edittext"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@drawable/edit_txt_bg"
                        android:hint="@string/phone"
                        android:inputType="number"
                        android:paddingTop="@dimen/filter_fragment_margin_horizontal"
                        android:textColor="@color/filter_text_active_color"
                        android:textSize="@dimen/filter_text_main"
                        app:mask="+7(###)###-##-##" />

</android.support.design.widget.TextInputLayout>

@VicMikhailau
Copy link
Owner

Hello, Parmakli .
Hello, Mkryglikov.

Sorry for the late reply.

Unfortunately, there is no way to devote much time to the project. Please feel free to Fork the project and add Pull requests.

Thanks a lot!

@madrazzl3
Copy link

madrazzl3 commented Mar 18, 2020

This one may help
#17 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants