2

大家好,我成功创建了自动完成编辑文本,但我想扩展/添加另一个字符串到现有单词。关于如何做到这一点的任何想法。

就像从下拉菜单中选择一个单词后,我应该能够在输入空格或逗号后添加另一个单词。

4

1 回答 1

1

感谢 Muhammed Babar 的建议,这是我对我的问题的回答。

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);

        }

    });
于 2013-06-20T08:04:20.960 回答