Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3441584
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:34:15+00:00 2026-05-18T08:34:15+00:00

I’m trying to replace MultiAutoCompleteTextView Drop down list with a ListView, which it should

  • 0

I’m trying to replace MultiAutoCompleteTextView Drop down list with a ListView, which it should have same functionality as drop down list, that means, when I click in one of items it should be added to MultiAutoCompleteTextView box, o so on, but filtering the ListView as you type.

So I came up with this raw code without success:

filterable_listview.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:layout_width="fill_parent" android:layout_height="fill_parent"
 android:orientation="vertical">

 <MultiAutoCompleteTextView
  android:layout_height="wrap_content" android:layout_width="fill_parent"
  android:hint="@string/To" android:id="@+id/search_box"></MultiAutoCompleteTextView>

 <ListView android:id="@android:id/list" android:layout_width="fill_parent"
  android:layout_height="fill_parent" android:layout_weight="1"/>

</LinearLayout>

AutoCompleteActivity.java

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.filterable_listview);
manager = new ContactManager();
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, manager.getContacts());

searchEdit = (MultiAutoCompleteTextView) findViewById(R.id.search_box);

searchEdit.addTextChangedListener(filterTextWatcher);

searchEdit.setTokenizer(new SpaceTokenizer());

setListAdapter(adapter);

getListView().setOnItemClickListener(
  new ListView.OnItemClickListener() {
  public void onItemClick(AdapterView<?> parent, View view,
                          int position, long id) {
                    //Here is one issues 
   searchEdit.append(adapter.getItem(position));
  }
 });
}

private TextWatcher filterTextWatcher = new TextWatcher() {
      public void afterTextChanged(Editable s) {
      }

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

      public void onTextChanged(CharSequence s, int start, int before, int count) {
           adapter.getFilter().filter(s);
      }

};

I have to main problems:

1) When I click an item, the whole selected text is appended,
I know the problem relies on:

searchEdit.append(adapter.getItem(position));

but, How can I do spanning text like regular autocomplete does ?

2) Once one item was selected, next input don’t show the suggestion any more (despite of SpaceTonekizer)

I hope my explanation was clear.

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:34:16+00:00Added an answer on May 18, 2026 at 8:34 am

    If someone need to do something like I needed, I made this

    private MultiAutoCompleteTextView searchEdit;
    
    private ArrayAdapter<String> adapter = null;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        adapter = new ArrayAdapter<String>(this,
                android.R.layout.simple_dropdown_item_1line, manager
                        .getContacts());
    
        setListAdapter(adapter);
    
        searchEdit = (MultiAutoCompleteTextView) findViewById(R.id.search_box);
    
        searchEdit.addTextChangedListener(filterTextWatcher);
    
        searchEdit.setTokenizer(new SpaceTokenizer());
    
        searchEdit.setAdapter(adapter);
    
        searchEdit.setOnClickListener(new OnClickListener() {
    
            public void onClick(View v) {
                String t = ((TextView) v).getText().toString();
                String f = searchEdit.getText().toString();
    
                int s = searchEdit.getSelectionStart();
                int i = s;
    
                while (i > 0 && f.charAt(i - 1) != ' ') {
                    i--;
                }
    
                adapter.getFilter().filter(t.substring(i, s));
            }
        });
    
        okButton = (Button) findViewById(R.id.ok);
        okButton.setOnClickListener(new OnClickListener() {
    
            public void onClick(View v) {
                Bundle stats = new Bundle();
                stats.putString("ConversationName", searchEdit.getText()
                        .toString());
    
                Intent i = new Intent();
                i.putExtras(stats);
                setResult(RESULT_OK, i);
                finish();
            }
        });
    
        searchEdit.setOnKeyListener(new OnKeyListener() {
    
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT
                        || keyCode == KeyEvent.KEYCODE_DPAD_RIGHT
                        || keyCode == KeyEvent.KEYCODE_DPAD_UP
                        || keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
    
                    String t = ((TextView) v).getText().toString();
                    String f = searchEdit.getText().toString();
    
                    int s = searchEdit.getSelectionStart();
                    int i = s;
    
                    while (i > 0 && f.charAt(i - 1) != ' ') {
                        i--;
                    }
    
                    adapter.getFilter().filter(t.substring(i, s));
    
                    return false;
                }
    
                return false;
            }
        });
    
        getListView().setOnItemClickListener(
                new ListView.OnItemClickListener() {
                    public void onItemClick(AdapterView<?> parent, View view,
                            int position, long id) {
    
                        String t = adapter.getItem(position);
                        String f = searchEdit.getText().toString();
    
                        int s = searchEdit.getSelectionStart();
                        int i = s;
    
                        while (i > 0 && f.charAt(i - 1) != ' ') {
                            i--;
                        }
    
                        searchEdit.getText().insert(s, t.substring(s - i));
                    }
                });
    }
    
    
        @Override
    protected void onDestroy() {
        super.onDestroy();
        searchEdit.removeTextChangedListener(filterTextWatcher);
    }
    
    
    private TextWatcher filterTextWatcher = new TextWatcher() {
    
        public void afterTextChanged(Editable s) {
            okButton.setEnabled(searchEdit.getText().toString().trim()
                    .length() > 0);
        }
    
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
        }
    
        public void onTextChanged(CharSequence s, int start, int before,
                int count) {
            adapter.getFilter().filter(s);
        }
    
    };
    
    
    
    public class SpaceTokenizer implements Tokenizer {
    
    public int findTokenStart(CharSequence text, int cursor) {
        int i = cursor;
    
        while (i > 0 && text.charAt(i - 1) != ' ') {
            i--;
        }
        while (i < cursor && text.charAt(i) == ' ') {
            i++;
        }
    
        return i;
    }
    
    public int findTokenEnd(CharSequence text, int cursor) {
        int i = cursor;
        int len = text.length();
    
        while (i < len) {
            if (text.charAt(i) == ' ') {
                return i;
            } else {
                i++;
            }
        }
    
        return len;
    }
    
    public CharSequence terminateToken(CharSequence text) {
        int i = text.length();
    
        while (i > 0 && text.charAt(i - 1) == ' ') {
            i--;
        }
    
        if (i > 0 && text.charAt(i - 1) == ' ') {
            return text;
        } else {
            if (text instanceof Spanned) {
                SpannableString sp = new SpannableString(text + " ");
                TextUtils.copySpansFrom((Spanned) text, 0, text.length(),
                        Object.class, sp, 0);
                return sp;
            } else {
                return text + " ";
            }
        }
    }
    }
    

    The xml looks like this:

        <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:orientation="vertical"
    android:drawingCacheQuality="high">
    
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:orientation="horizontal">
    
    
        <MultiAutoCompleteTextView
            android:layout_marginLeft="1dip"
            android:layout_marginTop="1dip"
            android:layout_height="wrap_content" 
            android:layout_weight="1"
            android:layout_width="fill_parent"
            android:dropDownHeight="0px" 
            android:hint="@string/To" 
            android:id="@+id/search_box"
            ></MultiAutoCompleteTextView>
    
    
    
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:text="Ok"
            android:id="@+id/ok"
            android:enabled="false"
            />  
    
    
    </LinearLayout>     
    <ListView android:id="@android:id/list" android:layout_width="fill_parent"
        android:layout_height="fill_parent" android:layout_weight="1" />
    
    </LinearLayout>
    

    Hope this help

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I have a text area in my form which accepts all possible characters from
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.