2017-05-10 92 views
0

我有要求將金額設置爲Google錢包格式。當用戶在edittext中輸入金額時。它會顯示下面的金額。我有很多搜索,但沒有得到任何解決方案。如果有人能幫助我,那對我很有幫助。Google電子錢包輸入提交

enter image description here

+0

你到目前爲止嘗試過什麼? –

+0

我嘗試過用三個editText在單獨的視圖中顯示所有數字。但我想在同一個edittext中的所有數字。 –

回答

0

你可以有一個EditText和格式化文本,以HTML爲用戶鍵入它。我不知道你怎麼知道是在仙用戶衝孔時,但該代碼可以看起來像:

editText.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 editable) { 
      if (editable.length() > 1) { 
       String htmlCode = doSomeMagicHereAndReturnFormattedString(editable.toString()); 
       Spanned spannedHtml; 
       if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { 
        spannedHtml = Html.fromHtml(htmlCode, Html.FROM_HTML_MODE_LEGACY); 
       } else { 
        spannedHtml = Html.fromHtml(htmlCode); 
       } 
       editText.setText(spannedHtml); 


      } 
     } 

     private String doSomeMagicHereAndReturnFormattedString(String s) { 
      // You need to change this to be formatted properly 
      String myHtml = "<html>" + s + "</html>"; 
      return myHtml; 
     } 

    }); 
相關問題