Extending ArrayAdapter in android

前端 未结 4 1428
Happy的楠姐
Happy的楠姐 2020-12-09 09:37

I need to override a getFilter() method from the class ArrayAdapter and i found the source code from here in the github

//package         


        
4条回答
  •  抹茶落季
    2020-12-09 09:55

    After some help from stackoverflow community i removed the exception and later i found out that the suggestions that are returned doesn't really change because the mObjects was returned from the super class or base class. The problem was the there were two public methods getCount() and getItem(int position) which gets the count and fetches the list from mObjects from the base class. So i just have to add those two methods in my class..

    public int getCount() {
        return mObjects.size();
    }
    
    public T getItem(int position) {
        return mObjects.get(position);
    }
    

    Now mObjects of the derived class will be returned. Which are the updated in the dropdown list in the UI.

    I am not a java expert, but this solves my problem. If you have any suggestions to make the code better please add it in comments or feel free to edit the answer.!

提交回复
热议问题