相关疑难解决方法(0)

android edittext onchange监听器

我知道一点点,TextWatcher但是对你输入的每一个角色都会发出火花.我想要一个在用户完成编辑时触发的监听器.可能吗?另外在TextWatcher我得到一个实例,Editable但我需要一个实例EditText.我怎么做到的?

编辑:第二个问题更重要.请回答.

android textwatcher android-edittext

102
推荐指数
4
解决办法
22万
查看次数

TextWatcher用于多个EditText

我想TextWatcher为多个EditText字段实现接口.目前我正在使用:

text1.addTextChangedListener(this);
text2.addTextChangedListener(this);
Run Code Online (Sandbox Code Playgroud)

然后重写我的Activity中的方法:

public void afterTextChanged(Editable s) {}

public void beforeTextChanged(CharSequence s, int start, int count, int after) {}
public void onTextChanged(CharSequence s, int start, int before, int count) 
{
 // do some operation on text of text1 field
 // do some operation on text of text2 field 
}
Run Code Online (Sandbox Code Playgroud)

然而,这工作正常但我正在寻找其他方法,以便我可以明确地确定当前关注的EditText字段SoftKeyboard.

android interface textwatcher android-edittext android-activity

65
推荐指数
5
解决办法
7万
查看次数

用于多个 EditText 字段的 TextWatcher

我有一些利用材质对话框库的代码;我有一个包含四个 EditText 字段(电子邮件、姓名、用户名、密码)的对话框。我希望它能够禁用对话框的“注册”按钮,除非所有字段中至少有一个字符。

我四处寻找,找到了一种方法;不幸的是,它似乎不起作用。例如,如果我拉出对话框并在任何单个字段中输入任何内容,则该按钮将变为启用状态。但是,如果我编辑一个字段,然后编辑另一个字段,然后删除其中一个字段中的文本,则该按钮将被禁用;如果我填写所有字段,然后删除单个字段内的文本,也会发生同样的情况。

我曾想过利用另一个建议(这将涉及编写我自己的私有内部类),但考虑到我会实现同样的目标(至少据我所知),我认为这并不重要。

        //registerDialog is a MaterialDialog object
        final View registerAction = registerDialog.getActionButton(DialogAction.POSITIVE);
        final EditText registerNameInput;
        final EditText registerEmailInput;
        final EditText registerUsernameInput;
        final EditText registerPasswordInput;
        if (registerDialog.getCustomView() != null) {
            registerNameInput = (EditText) registerDialog.getCustomView().findViewById(R.id.register_name);
            registerEmailInput = (EditText) registerDialog.getCustomView().findViewById(R.id.register_email);
            registerUsernameInput = (EditText) registerDialog.getCustomView().findViewById(R.id.register_username);
            registerPasswordInput = (EditText) registerDialog.getCustomView().findViewById(R.id.register_password);

            /*
             * TextWatcher lets us monitor the input fields while registering;
             * This make sure we don't allow the user to register with empty fields
             */
            TextWatcher watcher = new …
Run Code Online (Sandbox Code Playgroud)

android textwatcher android-edittext

2
推荐指数
1
解决办法
4317
查看次数

检查android中是否有任何edittext已更改

我的布局中有10个edittexts.有什么方法可以检查是否有任何edittext值被更改?我知道我可以使用afterTextChange等,但我想知道有任何一种方法可以检查所有edittexts吗?

android

0
推荐指数
1
解决办法
1404
查看次数