簡體   English   中英

用戶對其進行編輯后,如何獲取EditText的值?

[英]How to get value of EditText after it has been edited by a user?

我創建了一個EditText“ quantity”,其默認值為1。我想在用戶對其進行編輯后獲得EditText“ quantity”的最終值,而不是給我默認值(= 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){
               ///
             }
        }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM