监听TextView的变动

editText.addTextChangedListener(new TextWatcher() {
    @Override
    public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        Toast.makeText(MainActivity.this, "beforeTextChanged: " + editText.getText().toString() + "; Start: " + i + "; 变化前: " + i1 + "; 变化后: " + i2, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        Toast.makeText(MainActivity.this, "onTextChanged: " + editText.getText().toString() + "; Start: " + i + "; 变化前: " + i1 + "; 变化后: " + i2, Toast.LENGTH_SHORT).show();
    }

    @Override
    public void afterTextChanged(Editable editable) {
        Toast.makeText(MainActivity.this, "afterTextChanged: " + editText.getText().toString(), Toast.LENGTH_SHORT).show();
    }
});

ii1i2这三个参数有些诡异,i指的是从哪个位置开始变化,i1一般都是0,i2是新增加了多少字节。

你可能感兴趣的:(Android,textview,android)