繁体   English   中英

Android Studio库导入错误

[英]Android Studio library import error

所以我现在正在研究我的大学项目,并且需要在其上使用addTextChangedListener方法。 一开始没有任何问题,但是当我实现TextWatcher()时,它有一个红色下划线表示“无效的方法声明”。 并且覆盖方法得到“这里不允许注释”。 我不明白是什么导致了这个问题,所以如果你能帮助我,我会非常感激。

import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.text.TextWatcher;




public class MainActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    EditText activityTxt = (EditText) findViewById(R.id.txtActivity);
    EditText whereTxt = (EditText) findViewById(R.id.txtWhere);
    EditText whenTxt = (EditText) findViewById(R.id.txtWhen);
    EditText withTxt = (EditText) findViewById(R.id.txtWith);
    Button addBtn = (Button) findViewById(R.id.btnCreate);

    mobileNumber.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            mobileNumber.setError(null);
        }

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

        @Override
        public void afterTextChanged(Editable s) {
            mobileNumber.setError(null);
        }
    });

}

看起来您忘了定义: mobileNumber ,这应该是textEdit。 你的TextWatcher代码没有问题。

还请删除未使用的导入:

import android.support.annotation.IdRes;
import android.support.annotation.Nullable;

通过同时按CTRL + ALT + O优化导入

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM