我创建了一个默认值为 1 的 EditText“数量”。我想在用户编辑后获取 EditText“数量”的最终值,而不是给我默认值 (= 1)。
我怎样才能从这里做到这一点?
EditText quantity = (EditText)findViewById(R.id.quantity);
final int qty = Integer.valueOf(quantity.getText().toString()).intValue();
quantity.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) {
}
@Override
public void afterTextChanged(Editable s) {
}
});
最佳答案
从afterTextChanged(Editable s)
获取更新值
@Override
public void afterTextChanged(Editable s) {
try{
qty = Integer.valueOf(s.toString()).intValue();
}catch(Exception e){
///
}
}
关于java - 如何在用户编辑后获取 EditText 的值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32153113/