久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

【轉(zhuǎn)】android editText 輸入字?jǐn)?shù)限制

 techres 2010-11-15
android editText 輸入字?jǐn)?shù)限制
方法一:
         // 輸入框限制輸入字?jǐn)?shù)
        editText.addTextChangedListener(new TextWatcher() {
            private CharSequence temp;
            private boolean isEdit = true;
            private int selectionStart ;
            private int selectionEnd ;
            @Override
            public void beforeTextChanged(CharSequence s, int arg1, int arg2,
                    int arg3) {
                temp = s;
            }
           
            @Override
            public void on
TextChanged(CharSequence s, int arg1, int arg2,
                    int arg3) {
            }
           
            @Override
            public void afterTextChanged(Editable s) {
                 selectionStart = editText.getSelectionStart();
                selectionEnd = editText.getSelectionEnd();
                Log.i("gongbiao1",""+selectionStart);
                if (temp.length() > Constant.TEXT_MAX) {
                    Toast.makeText(KaguHomeActivity.this,
                            R.string.edit_content_limit, Toast.LENGTH_SHORT)
                            .show();
                    s.delete(selectionStart-1, selectionEnd);
                    int tempSelection = selectionStart;
                    editText.setText(s);
                    editText.setSelection(tempSelection);
                }
            }


        });


      方法二:
         利用EditText可以設(shè)置filter的特性,自定義一個(gè)LengthFilter,,當(dāng)輸入字?jǐn)?shù)超過限制時(shí) ,,做出自定義的提示
          // 輸入框限制輸入字?jǐn)?shù)
        InputFilter[] filters = new InputFilter[1];
        filters[0] = new InputFilter.LengthFilter(Constant.TEXT_MAX) {
            @Override
            public CharSequence filter(CharSequence source, int start, int end,
                    Spanned dest, int dstart, int dend) {
                if (source.length() > 0 && dest.length() == Constant.TEXT_MAX) {
                    if ((System.currentTimeMillis() - toastTime) > interval) {
                        toastTime = System.currentTimeMillis();
                        Toast
                                .makeText(KaguHomeActivity.this,
                                        R.string.edit_content_limit,
                                        Toast.LENGTH_SHORT).show();
                    }
                }
                if (dest.toString().equals(
                        getResources().getString(R.string.input_default_txt))) {
                    Bundle data = new Bundle();
                    data.putCharSequence("source", source);
                    Message message = textHandler.obtainMessage();
                    message.setData(data);
                    message.sendToTarget();
                }

                return super.filter(source, start, end, dest, dstart, dend);
            }
        };
        editText.setFilters(filters);
private Handler textHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {

            Bundle data = msg.getData();
            CharSequence source = data.getCharSequence("source");
            editText.setTextColor(Color.BLACK);
            editText.setText(source);
            editText.setSelection(source.length());
        }
    };

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn),。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式,、誘導(dǎo)購買等信息,謹(jǐn)防詐騙,。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類似文章 更多