Filtering a ListView with Baseadapter filters text not images

后端 未结 4 1852
一向
一向 2020-12-18 07:29

There was some progress made to the earlier problem. Now there is a new problem. The text in the GridView shows the correct result. However, the images are the same as at th

4条回答
  •  情深已故
    2020-12-18 08:22

    First refactor your code. Create a class that holds name, picture and other friend data together.

    class Friend {
        public String name;
        public String picture;
        ... /* more members and access methods*/
    };
    

    Then modify your adapter and filtering code accordingly.

    • FilterResults should contain the ArrayList, i.e. a list of Friend objects and not just the names.

    • In Adapter, replace

      List arrayListNames;
      List arrayPictures;

      with

      List friendsList;

    • Change the getView method to access data from the friendsList object list.

    After these changes the code will look better and work better.

    Update:

    Make sure your adapter's getItem method returns a Friend object

    public Object getItem(int position) {
        return mFriendsList.get(position);
    }
    

提交回复
热议问题