2012-06-11 32 views
0

我需要一個方法。請幫助我。Android上的自動完整蒙版EditTextView

我正在開發一個應用程序,我需要從用戶那裏得到價格作爲輸入。在那裏我需要帶有自動填充掩碼的EditTextView。

一樣,如果用戶希望鍵入100500,會有自動輸入值替換字符串,這是$ 100,500.00

我想,這也足以說明我需要的究竟是什麼。請在此建議我。謝謝。

回答

1

您可以像下面一樣在您的EditText上添加一個TextWatcher。在onTextChanged方法中,您將需要分析和修改用戶當前輸入(以CharSequence),然後更新您的EditText(text.setText(「yourModifiedText」))

EditText text = (EditText) findViewById(R.id.YOUR_ID); 
text.addTextChangedListener(textWatcher); 

private TextWatcher textWatcher = new TextWatcher() { 

    public void afterTextChanged(Editable s) { 
    } 

    public void beforeTextChanged(CharSequence s, int start, intcount, int after) { 
    } 

    public void onTextChanged(CharSequence s, int start, int before, 
      int count) { 

    } 
}