大家好我成功创建了一个自动完成编辑文本,但我想扩展/添加另一个字符串到现有单词。关于如何做到这一点的任何想法。
就像从下拉菜单中选择一个单词后,我应该能够在输入空格或逗号后添加另一个单词。
答案 0 :(得分:1)
感谢穆罕默德巴巴尔的建议,这是我对我的问题的答案。
Sms = (MultiAutoCompleteTextView) findViewById(R.id.message);
quickM = getResources().getStringArray(R.array.quickmessages);
//SMS message view autocomplete.........
ArrayAdapter<String> adapterMessage = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, quickM);
Sms.setAdapter(adapterMessage);
//Set Tokenizer for SMS editText MultiAutoTextView
Sms.setTokenizer(new MultiAutoCompleteTextView.Tokenizer() {
@Override
public CharSequence terminateToken(CharSequence arg0) {
// TODO Auto-generated method stub
return "";
}
@Override
public int findTokenStart(CharSequence arg0, int arg1) {
// TODO Auto-generated method stub
return 0;
}
@Override
public int findTokenEnd(CharSequence arg0, int arg1) {
// TODO Auto-generated method stub
return 0;
}
});
//Setting Sms edittext onclick listener class
Sms.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
String name = (String) arg0.getItemAtPosition(arg2);
if(Sms.getText().toString().length()==0)
Sms.setText(name);
else
Sms.setText(Sms.getText().toString()+","+name);
}
});