我不知道在我的应用程序中使用TextWatcher
我想获得两个拖曳编号的结果,而无需单击使用按钮
public class MainActivity extends AppCompatActivity {
EditText editText, editText1;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText = findViewById(R.id.et);
editText1 = findViewById(R.id.et1);
textView = findViewById(R.id.tv);
}
public void cal(View view) {
TextWatcher autoAddTextWatcher = new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
int value1 = Integer.parseInt(editText.getText().toString());
int value2 = Integer.parseInt(editText1.getText().toString());
int value3=value1 + value2;
textView.setText(Integer.toString(value3));
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
int value1 = Integer.parseInt(editText.getText().toString());
int value2 = Integer.parseInt(editText1.getText().toString());
int value3=value1 + value2;
textView.setText(Integer.toString(value3));
}
@Override
public void afterTextChanged(Editable s) {
int value1 = Integer.parseInt(editText.getText().toString());
int value2 = Integer.parseInt(editText1.getText().toString());
int value3=value1 + value2;
textView.setText(Integer.toString(value3));
}
};
editText.addTextChangedListener( autoAddTextWatcher);
editText1.addTextChangedListener(autoAddTextWatcher);
}
不幸的是停止了
答案 0 :(得分:1)
请使用logcat并告知确切错误是什么