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

  • SEARCH
  • Home
  • 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 4616980
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T02:03:33+00:00 2026-05-22T02:03:33+00:00

I have a list of categories that are stored as Strings in an ArrayAdapter

  • 0

I have a list of “categories” that are stored as Strings in an ArrayAdapter in my app. This much is pretty simple. The adapter is a field of the Activity and accessible everywhere. It is populated with values during onCreate().

I have a “Entry” Dialog that contains an AutoCompleteTextView which uses this adapter and works very well. This is basically a dialog to add new items to a list.

I also have a second Dialog which acts as a filter for my list and has a single Spinner which when the Dialog is created, uses the same ArrayAdapter. Here’s the problem.

If I use the filter Dialog before the entry Dialog, the Spinner is populated with all of the items from the adapter. Works well.

Any and every time I use the entry Dialog, the AutoCompleteTextView works properly.

The problem comes if I use the entry Dialog and select an item in the AutoCompleteTextView when it suggests something. After selecting a suggested item in the popup, even if I cancel the entry Dialog, the next time I bring up the filter Dialog, the Spinner initially shows the item that was last selected from the AutoCompleteTextView (instead of the first item in the adapter), and only displays that single item in the Spinner’s list if clicked/touched. The only way to fix it is to end the application and re-open it. I’m not getting any errors or anything in logcat that is helpful.

EDIT – Okay, I’ve removed the previous code to replace it with a simple test case that I produced. The bottom line is that I would like to know if this is a bug, or if if it is expected results. When a suggestion is selected in an AutoCompleteTextView, I can confirm that the ArrayAdapter that is linked to it has filtering applied so that it’s count is affected and the only items shown if the adapter is accessed in a Spinner will be those that were filtered down to. I also added button to display a toast to show that the count is affected. Type “te” in the autocomplete, select either Test entry. They try the spinner or click the button to see the adapter’s count is only 2.

So the final question is now… can the adapter’s filter be reset (other than by typing in and clearing the AutoCompleteTextView)? I can’t find any method to do this. I have worked around the problem in my actual app by setting up a temporary adapter, copying over the main adapters items and setting the views to use the temporary adapter instead. My phone is running 2.2, and I have tested as high as 2.3.3 API level 10 in an emulator.

The xml for main.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
<AutoCompleteTextView android:id="@+id/actv"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_centerHorizontal="true" />
<Spinner android:id="@+id/spinner"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_centerInParent="true" />
<Button android:id="@+id/button"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:text="Check It"
    android:layout_alignParentBottom="true"
    android:layout_centerInParent="true" />
</RelativeLayout>

The code for MainActivity.java

public class MainActivity extends Activity {
    /** Called when the activity is first created. */

    AutoCompleteTextView actv;
    Spinner spinner;
    Button button;

    String [] adapterList = {"Test1", "Test2", "Garbage1", "Garbage2"};

    ArrayAdapter<String> adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, adapterList);

        actv = (AutoCompleteTextView) findViewById(R.id.actv);
        spinner = (Spinner) findViewById(R.id.spinner);
        button = (Button) findViewById(R.id.button);

        actv.setAdapter(adapter);
        spinner.setAdapter(adapter);

        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(MainActivity.this, "" + adapter.getCount() + " Items in Adapter", Toast.LENGTH_SHORT).show();
            }
        });
    }
}
  • 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-22T02:03:34+00:00Added an answer on May 22, 2026 at 2:03 am

    Looking at AutoCompleteTextView source code, it does filter the ArrayAdapter:

    http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/widget/AutoCompleteTextView.java#AutoCompleteTextView.performFiltering%28java.lang.CharSequence%2Cint%29

    You may want to remove the filter on an onClick callback in the spinner:

    Filter filter = adapter.getFilter();
    filter = null;
    

    (see the setAdapter method in AutoCompleteTextView, around line 600)

    http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.2_r1.1/android/widget/ArrayAdapter.java#ArrayAdapter.getFilter%28%29

    Let me know if it works

    BTW, is the adapter going to change dynamically? You’re “workaround” of two adapters might be a better option than messing with the filter. What if the user starts a word, then clicks the spinner, cancels it and goes back to the word? Now the autocompletion will not make sense, unless you save the filter and restore it somehow.
    I do believe that two adapters (based on the same string array) is a better solution.

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

Sidebar

Related Questions

I have a list of categories that I publish to a UI from database.
I have a list of categories on my webpage. They are stored on mysql
I have a simple MySQL table thats contains a list of categories, level is
Let's say I have a list of categories for navigation on a web app.
Within an asp.net application I have a list of categories objects, within this list
I have a list of categories and want to display them if they are
i have list of rows that user select and i want to delete them,
I have a real estate website that has several categories. And i want the
I have already asked this question on SuperUser but it was suggested there that
I have a table that defines the possible categories in my website - fields

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.