3 回答
TA贡献1796条经验 获得超7个赞
使用文本更改侦听器在每次更改值时触发
inputScoreWe.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(s.length() > 0){
inputScoreYou.setText(162 - Integer.parseInt(inputScoreYou.getText().toString())+"");
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
TA贡献1811条经验 获得超6个赞
将您的代码替换为如下代码
inputScoreWe = findViewById(R.id.inputScoreWe);
inputScoreYou = findViewById(R.id.inputScoreYou);
inputScoreWe.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() > 0) {
inputScoreYou.setText(162 - Integer.parseInt(inputScoreYou.getText().toString()) + "");
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
inputScoreYou.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.length() > 0) {
inputScoreWe.setText(162 - Integer.parseInt(inputScoreWe.getText().toString()) + "");
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
TA贡献1796条经验 获得超4个赞
尝试这个
brandET = findViewById(R.id.addCar_brand);
modelET = findViewById(R.id.addCar_model);
brandET.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
brandChange = hasFocus;
}
});
modelET.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
modelChange = hasFocus;
}
});
brandET.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (brandChange && count > 0) {
int dataFromBrand = Integer.parseInt(s.toString());
modelET.setText((162 - dataFromBrand) + "");
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
modelET.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (modelChange && count > 0) {
int dataFromModel = Integer.parseInt(s.toString());
brandET.setText((162 - dataFromModel) + "");
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
这里brandET和modelET是你的两个编辑文本...brandChange和modelChange是两个全局布尔数据
添加回答
举报