0

我正在使用editname.addTextChangedListener(watcher)在android中调用editText的异步任务; 在我在编辑文本中输入字符后,它在 android 中不起作用。

 private final TextWatcher watcher=new TextWatcher(){
            @Override
            public void afterTextChanged(Editable s){
            if(s.length()<=4){
            Toast.makeText(getApplicationContext(), "type above 4 characters",  Toast.LENGTH_SHORT).show();
            }
            else{
                String url="http://10.0.2.2/chat/q.php?username="+s.toString();
                 if(task != null && (task.getStatus() == AsyncTask.Status.FINISHED)){
                task.execute(new String[]  {url});
                 }

            }
            }

            @Override
            public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                    int arg3) {


            }

            @Override
            public void onTextChanged(CharSequence arg0, int arg1, int arg2,
                    int arg3) {


            }

        };

我的问题是吐司不适用于我的代码。请帮助

4

2 回答 2

1

尝试这个-

Toast.makeText(YourActivity.this, "type above 4 characters", Toast.LENGTH_SHORT).show();

替换YourActivity为您的Activity.

于 2013-10-08T06:23:05.573 回答
0

除了getApplicationContext()在您的Toast.

 Toast.makeText(Mainactivity.this, "type above 4 characters",  Toast.LENGTH_SHORT).show();
于 2013-10-08T06:16:11.427 回答