Java import error “the type android.widget.Filter.FilterResults is not visible”

Java import error “the type android.widget.Filter.FilterResults is not visible” … here is a solution to the problem.

Java import error “the type android.widget.Filter.FilterResults is not visible”

This question has already been asked: the type android.widget.Filter.FilterResults is not visible
But there is no clear answer, and now I have the same problem. In that discussion, something was mentioned about variables being marked as final, and they shouldn’t be used for getFilters…
Well, here’s my code :

package com.example.project;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Locale;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.DisplayMetrics;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Filter;
import android.widget.Filter.FilterResults;
import android.widget.Filterable;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

public class PlacesMain extends Activity {

    protected void onCreate(Bundle savedInstanceState) {

PreferenceManager.setDefaultValues(this, R.xml.preferences, false);
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
        String localePref = sharedPref.getString("pref_locale", "");
        Configuration conf = getResources().getConfiguration();
        conf.locale = new Locale(localePref);
        DisplayMetrics metrics = new DisplayMetrics();
        Resources resources = new Resources(getAssets(), metrics, conf);


final ListView listview = (ListView) findViewById(;

final EditText edittext = (EditText) findViewById(;

String[] galilee = getResources().getStringArray(R.array.galilee_places);
        String[] judea = getResources().getStringArray(R.array.judea_places);

String[] galilee_en = new String[galilee.length];
        String[] judea_en = new String[judea.length];

if(localePref != "en"){
            Locale current = conf.locale;
            conf.locale = new Locale("en");
            metrics = new DisplayMetrics();
            Resources resources_en = new Resources(getAssets(), metrics, conf);
            galilee_en = resources_en.getStringArray(R.array.galilee_places);       
            judea_en = resources_en.getStringArray(R.array.judea_places);       
            conf.locale = current;
            resources = new Resources(getAssets(), metrics, conf);
            galilee_en = galilee;       
            judea_en = judea;       

final ArrayList<Item> galileeArrayList = new ArrayList<Item>();
        final ArrayList<Item> judeaArrayList = new ArrayList<Item>();
        final ArrayList<Item> allArrayList = new ArrayList<Item>();

for (int i = 0; i < galilee.length; ++i)
          galileeArrayList.add(new Item(galilee[i],galilee_en[i],i));
          allArrayList.add(new Item(galilee[i],galilee_en[i],i));
        for (int i = 0; i < judea.length; ++i)
          judeaArrayList.add(new Item(judea[i],judea_en[i],i));
          allArrayList.add(new Item(judea[i],judea_en[i],i));
        Collections.sort(galileeArrayList,new Comparator<Item>(){
            public int compare(Item o1, Item o2){
                return o1.getPlace().compareTo(o2.getPlace());
        Collections.sort(judeaArrayList,new Comparator<Item>(){
            public int compare(Item o1, Item o2){
                return o1.getPlace().compareTo(o2.getPlace());
        Collections.sort(allArrayList,new Comparator<Item>(){
            public int compare(Item o1, Item o2){
                return o1.getPlace().compareTo(o2.getPlace());

final ItemAdapter all_adapter = new ItemAdapter(this, android. R.layout.simple_list_item_1,allArrayList);
        final ItemAdapter galilee_adapter = new ItemAdapter(this, android. R.layout.simple_list_item_1,galileeArrayList);
        final ItemAdapter judea_adapter = new ItemAdapter(this, android. R.layout.simple_list_item_1,judeaArrayList);


edittext.addTextChangedListener(new TextWatcher(){
                public void onTextChanged(CharSequence s, int start, int before, int count) {

 TODO Auto-generated method stub
                   String mytext = edittext.getText().toString();

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

 TODO Auto-generated method stub

                public void afterTextChanged(Editable s) {

 TODO Auto-generated method stub

private class ItemAdapter extends ArrayAdapter<Item> implements Filterable {
        private final Object mLock = new Object();
        private ItemsFilter mFilter;
        private ArrayList<Item> mItems;

public ItemAdapter(Context context, int textViewResourceId, ArrayList<Item> mItems) {
            super(context, textViewResourceId, mItems);
            this.mItems = mItems;

        public View getView (int position, View convertView, ViewGroup parent) {
            View view = super.getView(position, convertView, parent);
            Item i = mItems.get(position);
            if(i != null){
                TextView text1 = (TextView) view.findViewById(android.;
            return view;

public Filter getFilter(){
            if (mFilter == null){
                mFilter = new ItemsFilter();
            return mFilter;

private class ItemsFilter extends Filter {
            protected FilterResults performFiltering(CharSequence prefix) {
                Initiate our results object
                FilterResults results = new FilterResults();
                 If the adapter array is empty, check the actual items array and use it
                if (mItems == null) {
                    synchronized (mLock) { // Notice the declaration above
                        mItems = new ArrayList<Item>();
                 If no prefix is sent to the filter we'll send back the original array
                if(prefix == null || prefix.length() == 0){
                    synchronized (mLock) {
                        results.values = mItems;
                        results.count = mItems.size();
                     compare lower case strings
                    String prefixString = prefix.toString().toLowerCase();
                    ArrayList<Item> items = mItems;
                    final int count = items.size();
                    final ArrayList<Item> newItems = new ArrayList<Item>(count);
                    for (int i = 0; i < count; i++){
                        final Item item = items.get(i);
                        final String itemPlace = item.getPlace().toLowerCase();
                         First match against the whole, non splitted value
                        if (itemPlace.startsWith(prefixString)){
                             TODO this index won't be correct, need separate index from loop increment
                            newItems.add(new Item(item.getPlace(),item.getPlaceEn(),i));

                     Set and return
                    results.values = newItems;
                    results.count = newItems.size();
                return results;

            protected void publishResults(CharSequence prefix, FilterResults results){
                noinspection unchecked
                mItems = (ArrayList<Item>) results.values;
                 Let the adapter know about the updated list
                if(results.count > 0){


This is the main part of the code, and I’ve removed the other parts that aren’t too interested in this issue (the buttons and their touch listeners).
I didn’t have any errors other than the import of android.widget.Filter.FilterResults;
I tried to remove “final” from the adapter, but this gave me the error saying they have to be final. I tried removing “final” from ArrayLists, but that didn’t change anything, and there was still the error “android.widget.Filter.FilterResults type not visible” in the import.
What’s wrong with that?

I’m using my own custom Item class:

public class Item {
    private String place;
    private String placeEn;
    private int id;

public Item(String place, String placeEn, int id) { = place;
        this.placeEn = placeEn; = id;
    public String getPlace() {
        return place;
    public String getPlaceEn() {
        return placeEn;
    public int getId(){
        return id;
    public void setPlace(String place){ = place;
    public void setPlaceEn(String placeEn){
        this.placeEn = placeEn;
    public void setId(int id){ = id;

And I can’t ask what the solution is on other posts because I don’t have enough “reputation” here yet to comment, uh.


Based on my previous comment on the original question, come back here to mark it as answered:

Eclipse automatically adds the unwanted “import android.widget.Filter.FilterResults; After “Import android.widget.Filter”. Having “import android.widget.Filter” is sufficient, so just comment out or delete the second import of Filter.FilterResults.
Once I did, there were no more bugs and everything worked as expected.

Related Problems and Solutions