Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 约夫努尔斯(0) 过滤器=空 } } 重写更改前的乐趣(s:CharSequence?,p1:Int,p2:Int,p3:Int){ } 重写有趣的文本更改(p0:CharSequence?,p1:Int,p2:Int,p3:Int){ } })_Android_Android Edittext - Fatal编程技术网

Android 约夫努尔斯(0) 过滤器=空 } } 重写更改前的乐趣(s:CharSequence?,p1:Int,p2:Int,p3:Int){ } 重写有趣的文本更改(p0:CharSequence?,p1:Int,p2:Int,p3:Int){ } })

Android 约夫努尔斯(0) 过滤器=空 } } 重写更改前的乐趣(s:CharSequence?,p1:Int,p2:Int,p3:Int){ } 重写有趣的文本更改(p0:CharSequence?,p1:Int,p2:Int,p3:Int){ } }),android,android-edittext,Android,Android Edittext,Kotlin语言--要检查最大单词数,需要检查总空间 -->第一步 -->步骤2 edt.addTextChangedListener(对象:TextWatcher{ 覆盖后文本更改(s:可编辑?){ 变量计数:Int=0 如果(s.toString().length>0) 对于(0..s.toString()中的i.length-1){ 如果(s.toString()[i].toString()=“”){ 计数++ } 如果(i>1&&s.toString()[i-1].toString()

Kotlin语言--要检查最大单词数,需要检查总空间

-->第一步

-->步骤2


edt.addTextChangedListener(对象:TextWatcher{
覆盖后文本更改(s:可编辑?){
变量计数:Int=0
如果(s.toString().length>0)
对于(0..s.toString()中的i.length-1){
如果(s.toString()[i].toString()=“”){
计数++
}
如果(i>1&&s.toString()[i-1].toString()==“”&s.toString()[i].toString()==“”){
计数--
}
}
如果(计数>=MAX\u计数\u字){
filter=InputFilter.LengthFilter(edt.text.toString().length)
edt.filters=arrayOf(过滤器?:返回)
}
else if(过滤器!=null){
edt.filters=arrayOfNulls(0)
过滤器=空
}
}
重写更改前的乐趣(s:CharSequence?,p1:Int,p2:Int,p3:Int){
}
重写有趣的文本更改(p0:CharSequence?,p1:Int,p2:Int,p3:Int){
}
})


请完整阅读问题。我知道这会受到字符数的限制,我需要用单词来控制它count@Ram用后文本更改(可编辑)而不是前文本更改编写代码。请完整阅读问题。我知道这会受到字符数的限制,我需要用单词来控制它count@Ram用后文本更改(可编辑的s)而不是前文本更改来编写代码。用xml中的maxLength来代替。maxLength有什么问题吗?@Redman:它不是重复的,我需要用文字来控制它count@KiranBennyJoseph:它将限制字符数,而不是使用xml中的maxLength。maxLength有什么问题?@Redman:它不是重复的,我需要用word控制它count@KiranBennyJoseph:它将限制字符计数@Ram的可能重复,我已经编辑了我的anwswer,请将其签出。edittext.getText().toString().length()将给出总字符数,而不是wordcount@Ramcheck:@Ram,我已经编辑了我的anwswer,请签出它。edittext.getText().toString().length()将给出总字符数而不是单词数count@Ram检查:如果有两个连续的空格,这将不起作用。@theblitz为什么我们要在两个空格之间加上两个空格words@KiranBennyJoseph它确实发生了。有时人们会不小心把一个额外的空白。只需添加前一个字符的检查,以确保它不是空的。@KiranBennyJoseph检查s.equals(“”)将永远不会返回true,s将始终包含您输入的全部文本。我同意@theblitz Comments。如果有两个连续的空格,这将不起作用。@theblitz为什么要在两个空格之间加上两个空格words@KiranBennyJoseph它确实发生了。有时人们会不小心把一个额外的空白。只需对前一个字符添加一个检查,以确保它不是空的。@KiranBennyJoseph检查s.equals(“”)将永远不会返回true,s将始终包含您输入的全部文本。我同意@theblitz注释
editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int start, int count, int after) {

                int wordsLength = countWords(charSequence.toString());// words.length;
                // count == 0 means a new word is going to start
                if (count == 0 && wordsLength >= MAX_WORD_LIMIT) {
                    int charLength = mDescription.getText().length();
                    setCharLimit(mDescription, charLength > 0 ? charLength - 2 : charLength);
                } else {
                    removeFilter(mDescription);
                }
private InputFilter filter;

    private void setCharLimit(EditText et, int max) {
        filter = new InputFilter.LengthFilter(max);
        et.setFilters(new InputFilter[]{filter});
    }

    private void removeFilter(EditText et) {
        if (filter != null) {
            et.setFilters(new InputFilter[0]);
            filter = null;
        }
    }
android:maxLength="50"
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 s) {
           // Check your edittext length here
           if (edittext.getText().toString().length() > 100)
              edittext.setText(edittext.getText().toString().substring(0, 100);
        }
    });
    edittext.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

   @Override
   public void onTextChanged(CharSequence charSequence, int start, int before, int count) {

            //To fix word count
            String yourText= editText.getText().toString().replace(String.valueOf((char) 160), " ");
            if (yourText.split("\\s+").length > MAX_WORD_LIMIT ) {

                int space = 0;
                int length = 0;
                for (int i = 0; i < yourText.length(); i++) {
                    if (yourText.charAt(i) == ' ') {
                        space++;
                        if (space >= MAX_WORD_LIMIT) {
                            length = i;
                            break;
                        }

                    }
                }
                if (length > 1) {
                    editText.getText().delete(length, yourSelf.length()); // deleting last space
                    setCharLimit(editText, length - 1); //or limit edit text
                }
            } else {
                removeFilter(editText);
            }


        }

            @Override
            public void afterTextChanged(Editable s) {

        });
          private InputFilter filter;

          private void setCharLimit(EditText et, int max) {
            filter = new InputFilter.LengthFilter(max);
            et.setFilters(new InputFilter[] { filter });
            }

          private void removeFilter(EditText et) {
            if (filter != null) {
              et.setFilters(new InputFilter[0]);
             filter = null;
             }
           }
String text = "More than 100 word sentence";
String[] txtArr = text.split(" ");
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 s) {

               if (edittext.getText().toString().split(" ").size() > 100)
                  edittext.setText(edittext.getText().toString().substring(0, edittext.getText().toString().indexOf(edittext.getText().toString().split(" ").get(100))));
            }
        });
var filter: InputFilter?=null

edt.addTextChangedListener(object : TextWatcher {
            override fun afterTextChanged(s: Editable?) {

                var count : Int = 0

                if(s.toString().length > 0)

                    for(i in 0..s.toString().length-1){

                        if(s.toString()[i].toString() == " "){
                            count++
                        }

                        if(i > 1 && s.toString()[i-1].toString() == " " && s.toString()[i].toString() == " "){
                            count--
                        }

                    }

                if (count >= MAX_COUNTS_WORDS){
                    filter = InputFilter.LengthFilter(edt.text.toString().length)
                    edt.filters = arrayOf<InputFilter>(filter ?: return)
                }
                else if (filter != null) {
                    edt.filters = arrayOfNulls(0)
                    filter = null

                }


            }

            override fun beforeTextChanged(s: CharSequence?, p1: Int, p2: Int, p3: Int) {
            }

            override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {
            }

        })