我想輸入後輸入的文本。我已經完成了使用TextWatcher
。Android EditText:輸入文字
有一些問題:
例如,我想輸入32.5。在該方法中,我想添加到SET<Product>
。
這裏每個&每一批自己的儲蓄object.That意味着進入後3及其附加產品的對象爲SET,然後加入2然後還加入...
我想避免。一旦我完成進入EditText
,然後希望把它:
final EditText txtQty = new EditText(this);
txtQty.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
Log.v("TAG", "afterTextChanged" + s.toString());
String enterdPrice = txtPrice.getText().toString();
double remainQty =0.00;
Product enterdProduct = new Product();
try{
String enteredQty = s.toString();
enterdProduct.setProductCode(txtCode.getText().toString());
enterdProduct.setPrice(Double.parseDouble(enterdPrice));
//enterdProduct.setQty(Double.parseDouble(enteredQty));
// TO-DO
if (productSet.contains(enterdProduct)) {
productSet.remove(enterdProduct);
}
productSet.add(enterdProduct);
System.out.println("SIZE --" + productSet.size());
}
catch (Exception e) {
e.printStackTrace();
}
});
請給我的想法,我們怎樣才能獲得的EditText輸入一次我enetred文字?
並非總是按下ENTER鍵。您也可以將焦點切換到另一個字段。 –