2017-09-14 37 views
-2

我正在構建一個結帳活動,用戶在一個或多個EditText中輸入值(數字)。在活動的底部,我需要用所有EditText的總和來更新總值。在輸入EditText時刷新TextView

我試圖用這樣的TextWatcher:

@Override 
     public void afterTextChanged(final Editable arg0) { 
      if(!arg0.toString().equals(current)){ 
         String bottom_value = total_value.getText().toString(); 
         String number_total = bottom_value.replaceAll("[^0-9]", "");//remove $ 
         String value_arg = arg0.toString(); 
         String number_arg = value_arg.replaceAll("[^0-9]", "");//remove $ 

         int final_int = Integer.parseInt(number_arg)+ Integer.parseInt(number_total); 
         total_value.setText(Integer.toString(final_int)); 
      } 
     } 

但問題是,當用戶鍵入超過1個number.If您鍵入1比2,終值需要爲12,但我的代碼是3(總和1和2)。

對不起,我的英語,如果你不明白的東西評論,我可以更好地解釋。

HERE是我的應用程序的一個例子。

+0

安置自己的完整代碼,使人們可以幫助 –

回答

3

替換此

int final_int = Integer.parseInt(number_arg)+ Integer.parseInt(number_total); 

int final_int = Integer.parseInt(number_arg+number_total);