码迷,mamicode.com
首页 > 其他好文 > 详细

EditText判断用户输入完成,然后进行操作解决方案

时间:2016-01-14 20:47:45      阅读:135      评论:0      收藏:0      [点我收藏+]

标签:

private Timer timer = new Timer();
private final long DELAY = 1000; // in ms
EditText editTextStop = (EditText) findViewById(R.id.editTextStopId);
    editTextStop.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
        }
        @Override
        public void onTextChanged(final CharSequence s, int start, int before,
                int count) {
            if(timer != null)
                timer.cancel();
        }
        @Override
        public void afterTextChanged(final Editable s) {
            //avoid triggering event when text is too short
            if (s.length() >= 1) {              

                timer = new Timer();
                timer.schedule(new TimerTask() {
                    @Override
                    public void run() {
                        // TODO: do what you need here (refresh list)
                        // you will probably need to use
                        // runOnUiThread(Runnable action) for some specific
                        // actions
                     
                    }

                }, DELAY);
            }
        }
    });

EditText判断用户输入完成,然后进行操作解决方案

标签:

原文地址:http://www.cnblogs.com/shuijilove/p/5131486.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!