How to use the TextWatcher class in Android?

前端 未结 9 1129
独厮守ぢ
独厮守ぢ 2020-11-22 02:30

Can anyone tell me how to mask the substring in EditText or how to change EditText substring input to password type

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 02:53

    A little bigger perspective of the solution:

    @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View v = inflater.inflate(R.layout.yourlayout, container, false);
            View tv = v.findViewById(R.id.et1);
            ((TextView) tv).addTextChangedListener(new TextWatcher() {
                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                     SpannableString contentText = new SpannableString(((TextView) tv).getText());
                     String contents = Html.toHtml(contentText).toString();
                }
    
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
    
                    // TODO Auto-generated method stub
                }
    
                @Override
                public void afterTextChanged(Editable s) {
    
                    // TODO Auto-generated method stub
                }
            });
            return v;
        }
    

    This works for me, doing it my first time.

提交回复
热议问题