问题描述
我必须设置一些predefined值 MultiAutoCompleteTextView
(之前,我建议从下拉列表中选择)。这就像,因为如果你从下拉列表中选择2-3个项目。设置这些predefined值后,我再次想继续从列表过滤的正常进程,并将其添加到 MultiAutoCompleteTextView
。
I have to set some predefined values to MultiAutoCompleteTextView
(before I select from suggestion drop down list). It's like, as if you selected 2-3 items from drop-down list. After setting these predefined values, again I want to continue with normal process of filtering from the list and add it to MultiAutoCompleteTextView
.
它看起来像这样
Predefined1, Predefined2, Predefined3,
如果我做的setText(...)就如同使用的TextView
或的EditText
,具有一定的逗号分隔价值观,将其视为1整个单词,并在末尾添加一个逗号。
If I do setText(...) as you do with TextView
or EditText
, with some comma separated values, its considering it as 1 whole word and adding a comma at the end.
请建议我怎么能实现它。
Please suggest how can I implement it.
编辑:
好吧。让我详细解释。我想实现像this和。但是,从这1个额外的要求是,随着从建议选择价值降了下来,我还需要设置一些predefined值显示查看时,当我写的东西和preSS输入/隐藏键盘,无论我写应该转换成按钮文本。
如果这是不可能的,任何其他的选择吗?请建议。
Okay. Let me explain in detail. I am trying to achieve like in this and this. But, 1 extra requirement from this is that, along with selecting value from suggestion drop down, I also need to set some predefined values when View is displayed and when I write something and press enter/hide keyboard, whatever i wrote should be converted into button text.If it's not possible, any other alternative? Please suggest.
编辑:
这些值应该是有鉴于而不降下来选择。后来,取其用户的建议添加降了下来,这些也应该被添加到列表中。
These values should be there in view without selecting from drop down. Later, whichever users add from suggestion drop down, those also should be added to list.
这就像设置提示或一些文字的EditText
之前用户开始输入。
It's like setting hint or some text to EditText
before user starts typing.
感谢。
推荐答案
请尝试以下操作:
ArrayList<String> data=new ArrayList<String>();
data.add("Predefined1");
data.add("Predefined2");
data.add("Predefined3");
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_dropdown_item_1line, data.toArray());
MultiAutoCompleteTextView textView = (MultiAutoCompleteTextView) findViewById(/*View id*/);
MultiAutoCompleteTextView.CommaTokenizer tokenizer=new MultiAutoCompleteTextView.CommaTokenizer();
textView.setAdapter(adapter);
textView.setTokenizer(tokenizer);
textView.setOnEditorActionListener(new TextView.OnEditorActionListener(){
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
data.add(v.getText().toString());
adapter.notifyDataSetChanged();
return true;
}
return false;
}
});
textView.setText("Predefined1,");
tokenizer.terminateToken("Predefined1");
textView.setText(textView.getText().toString()+"Predefined2,");
tokenizer.terminateToken("Predefined2");
textView.setText(textView.getText().toString()+"Predefined3,");
tokenizer.terminateToken("Predefined3");
这篇关于设置predefined值MultiAutoCompleteTextView:Android的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!