Rishi
Rishi

Reputation: 3539

android autocompletetextview issue

i have a autocompletetextview in which i have attached a listview to show the query results. My problem is that once user selects a result i append it in the autocompletetextview.All the entries are seperated by a "," what i need is if user presses space in virtual keyboard i need to replace it with ",".

predestination.addTextChangedListener(new TextWatcher() {

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            // TODO Auto-generated method stub
        }

    });

i think i need to check it in this listener but this give me whole CharSequence of the enterd text but i need to check only spacebar .

Thanks

Upvotes: 0

Views: 148

Answers (1)

Joe
Joe

Reputation: 2243

If I understood your question correctly , maybe you can try something like

        @Override
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            String text = s.toString();
            if (text.length()>0) {
                if (text.charAt(text.length()-1)==' ') {
                    editText.setText(text.trim()+',');
                    editText.setSelection(text.length());
                }
            }
        }

using TextChangedListener like you said..

Upvotes: 1

Related Questions