Search code examples
androidlistviewfilteradaptersearchview

Android searchView not searching the list until fully scrolled


I have a listview with a custom adapter, and Im trying to use SearchView with a CustomFilter. But the search is not "fully" working.

When I search for something that is on the viewable area of the listview, it is able to search, and all nonviewable area is not being included in the search.

Here is a video on whats going on:

https://youtu.be/2Z9FZMlNmGw

main

public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.fragment_board_game_list, container, false);
        this.listView = (ListView) view.findViewById(R.id.listView);

        DatabaseAccess databaseAccess = DatabaseAccess.getInstance(this.getContext());
        databaseAccess.open();

        List<String> boardgamesNames = databaseAccess.getNames();
        List<String> urls = databaseAccess.getUrls();

        adapter = new bgAdapter(getContext(), R.layout.row_layout);
        adapterOriginal = new bgAdapter(getContext(), R.layout.row_layout);
        databaseAccess.close();
        listView.setAdapter(adapter);

        int i = 0;
        for(String name: boardgamesNames) {

            boardgameListRow data = new boardgameListRow(urls.get(i), boardgamesNames.get(i));
            i++;
            adapter.add(data);
            adapterOriginal.add(data);
        }

        listView.setDivider(null);
        listView.setDividerHeight(0);

        searchView = (SearchView)view.findViewById(R.id.searchId);
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {

                if (newText.length() > 0) {
                    adapter.getFilter().filter(newText);
                }

                return false;
            }
        });

        searchView.setOnCloseListener(new SearchView.OnCloseListener() {
            @Override
            public boolean onClose() {

                BoardGameListFragment fragment= new BoardGameListFragment();
                FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
                fragmentTransaction.replace(R.id.fragment_container,fragment);
                fragmentTransaction.commit();
                //adapter = adapterOriginal;
                return true;
            }
        });
        // Inflate the layout for this fragment
        return view;
    }
}

Here is the Adapter:

https://github.com/Shank09/AndroidTemp/blob/master/bgAdapter.java


Solution

  • I fixed it, I was using the wrong variable in bgAdapter. Please remove this question if possible.