Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/178.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 如何将阈值设置为EditText?_Android_Threshold - Fatal编程技术网

Android 如何将阈值设置为EditText?

Android 如何将阈值设置为EditText?,android,threshold,Android,Threshold,比如说,当用户开始在编辑文本中键入内容时,直到用户键入了20个字符,自动完成功能才会出现 我尝试将以下代码放入布局XML文件中,但无效: android:completionThreshold="20" 我也在Java类中尝试了以下方法,但也不起作用: myedittext.setThreshold(20); // it says 'The method setThreshold(int) is undefined for the type EditText' 编辑: 看来我的问题可能被误解

比如说,当用户开始在
编辑文本中键入内容时,直到用户键入了20个字符,自动完成功能才会出现

我尝试将以下代码放入布局XML文件中,但无效:

android:completionThreshold="20"
我也在Java类中尝试了以下方法,但也不起作用:

myedittext.setThreshold(20);
// it says 'The method setThreshold(int) is undefined for the type EditText'
编辑:

看来我的问题可能被误解了,所以我想澄清一下:

用户在编辑文本中键入一个单词。你知道“自动完成”在大约一个字符后是如何出现的吗?我不希望它这么快就出现。。。我的目标是让它只在用户输入了一定数量的字符后出现。。。差不多就是这样

为误会道歉。谢谢。

您使用的是常规的
编辑文本吗?这可能是个问题,因为前一个才是最重要的

但是,根据您对该问题的最新更新,在用户键入X个字母后,动态输入
EditText
的类型(尽管我从未尝试过)。大概是这样的:

myEditText.addTextChangedListener(new TextWatcher() {
    public void onTextChanged(CharSequence s, int start, 
            int before, int count) {}

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

    public void afterTextChanged(Editable s) {
        String text = myEditText.getText().toString();
        int maxChar = 5;

        // Suggest words if the word is long enough,
        // or prevent suggestions if not log enough
        int type = text.length() > maxChar ? 
                TYPE_TEXT_FLAG_AUTO_CORRECT : 
                TYPE_TEXT_FLAG_NO_SUGGESTIONS;

        myEditText.setInputType(type);
    }
});

现在的问题是你要尝试一下,看看是否适合你。

@Fuchsia:只需参考答案中的第一个链接。我做了。。。我还在找,但我不太明白>.@Fuchsia,检查我的第一个链接。将
EdtiText
替换为
AutoCompleteTextView
并利用其优势非常简单。只需在布局中替换它,然后在Java代码中执行类似于我的第一个link.Hrm上的代码段的操作。。。在链接中,我要创建自己的字符串数组,对吗?但是如果我想用字典?比方说,这与在信息中键入单词几乎是一样的,只是这些单词只有在您键入一定数量的字符后才会显示…@Fuchsia:这是一个不同的问题。我认为,你指的是系统的预测性打字。除非实现自己的键盘,否则无法更改其行为。