3 回答

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超7個(gè)贊
使用文本更改偵聽器在每次更改值時(shí)觸發(fā)
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貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個(gè)贊
將您的代碼替換為如下代碼
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貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超4個(gè)贊
嘗試這個(gè)
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是你的兩個(gè)編輯文本...brandChange和modelChange是兩個(gè)全局布爾數(shù)據(jù)
添加回答
舉報(bào)