Android的多的EditText无法实现监听器 [英] Android Multiple EditText can't implement listener

查看:94
本文介绍了Android的多的EditText无法实现监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有了解如何控制我的听众散装的几个问题。我已经成功地得到堆栈溢出,但EditText上一些工作是推动我nutts。

hi I'm having a few problems understanding how to control my listeners in bulk. I've managed to get a few working from Stack Overflow but EditText is driving me nutts.

我有3个editTexts,他们都愉快地工作,如果我idenpentatly输入code,但我想他们包裹起来都成一个方法用一个开关情况。

I have 3 editTexts and they all work happily if I idenpentatly enter the code, but I want to wrap them all up into one method with a switch case.

在此刻我的code一EditText上看起来像这样(和两个它有点乱)

at the moment my code for one edittext looks like so (and with two more its a bit messy)

intTextValue = (EditText)findViewById(R.id.intervalValue);
      intTextValue.addTextChangedListener(new TextWatcher() {

            @Override
            public void afterTextChanged(Editable s) {
                // TODO Auto-generated method stub
Double.parseDouble(intTextValue.getText().toString());

                if (textViewTouchIsHuman == true) {
                    intSeekValue = Double.parseDouble(intTextValue.getText().toString());
                    calculateWorkings();
                }
                textViewTouchIsHuman = true;    
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
                // TODO Auto-generated method stub

            }

          });

我使用setOnKeyListener,setOnClickListern,addtextchangedlistenr尝试,但我不能让任何人的工作?我希望这个问题让senese。感谢在进阶

I've tried using setOnKeyListener, setOnClickListern, addtextchangedlistenr but I can't get any of them to work? I hope that question makes senese. thank in adv.

推荐答案

为什么不做出TextWatcher的分配方法addTextChangedListener()之外,然后分配了TextWatcher多个的EditText对象。

Why not make a TextWatcher outside of the assigning method addTextChangedListener() and then assign that TextWatcher to multiple EditText objects.

例如:

TextWatcher tw = new TextWatcher();
intTextValue.addTextChangedListener(tw);
otherEditText.addTextChangedListener(tw);
...

这篇关于Android的多的EditText无法实现监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆