-2

I am using DataSet to get & set the value. Now I need to implement SearchView for filtering. SearchQuery is passed like "abcd". But how I compare "abcd" String with the datas are in List DataSet. I tried to get it by using contains & equals. But it didn't work.

private void SEARCH_QUERY(String strSearch) {

    String NEWTEXT = strSearch.trim();

    if (RestaurantDataSet.equals(NEWTEXT)) {

        RestaurantDataSet = new ArrayList<>();

        for (int i = 0; i < RestaurantDataSet.size(); i++) {

            String PRODUCTID = String.valueOf(RestaurantDataSet.get(i).getIG_PRODUCTID());
            String PRODUCTNAME = RestaurantDataSet.get(i).getIG_PRODUCTNAME();
            String CATEGORY_NAME = RestaurantDataSet.get(i).getIG_CATEGORYNAME();
            String CAT_ID = RestaurantDataSet.get(i).getIG_CATEGORY_ID();
            String IMG_ID = String.valueOf(RestaurantDataSet.get(i).getIG_IMAGEURL());
            int LIKE = RestaurantDataSet.get(i).getIG_LIKECOUNT();
            String PRICE = RestaurantDataSet.get(i).getIG_SALES_PRICE();
            String VOUCHER_ID = RestaurantDataSet.get(i).getIG_VOUCHER_ID();

            Restaurant_Beam item = new Restaurant_Beam();

            item.setIG_LIKECOUNT(LIKE);
            item.setIG_PRODUCTID(PRODUCTID);
            item.setIG_SALES_PRICE(PRICE);
            item.setIG_VOUCHER_ID(VOUCHER_ID);
            item.setIG_CATEGORY_ID(CAT_ID);
            item.setIG_IMAGEURL(IMG_ID);
            item.setIG_PRODUCTNAME(PRODUCTNAME);
            item.setIG_CATEGORYNAME(CATEGORY_NAME);

            RestaurantDataSet.add(item);
        }

        adapter = new CardAdapter(RestaurantDataSet, context);
        recyclerView.setAdapter(adapter);
        adapter.notifyDataSetChanged();
    }
}
Parama Sudha
  • 2,583
  • 3
  • 29
  • 48

2 Answers2

1

Full solution is provided here for getting Search Action in your app. Step by step implementation is provided for search, if you still need any clarification you can ask. Please check

How to filter a RecyclerView with a SearchView

Community
  • 1
  • 1
Android Geek
  • 8,956
  • 2
  • 21
  • 35
1

Recyclerview is basically an advanced version of the list view. It has all the features of a ListView and also, it is more flexible a with large data set than ListView. Adding search functionality in RecyclerView can give users power to search/filter a keyword from a large set of data collection without the hassle of scrolling the list till he finds the desired entity.answer and sample code Stackoverflow and github

Community
  • 1
  • 1
Muhammad Waleed
  • 2,517
  • 4
  • 27
  • 75