0

I'm trying to add empty view when data search is not found

SearchManager searchManager = (SearchManager)getActivity().getSystemService(Context.SEARCH_SERVICE);
        MenuItem item = menu.findItem(R.id.searchpemilik_bar);
        searchViewx = (SearchView)item.getActionView();
        searchViewx.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
        searchViewx.setMaxWidth(Integer.MAX_VALUE);
        searchViewx.setQueryHint("Cari...");
        searchViewx.setBackgroundResource(R.drawable.draw_form);

        searchViewx.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {

                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                newText = newText.toLowerCase();
                List<List_Pemilih> mynewList = new ArrayList<>();
                for (List_Pemilih model: listPemilih){
                    String namapemilih = model.getNama().toLowerCase();

                    String kecamatanpemilih = model.getKecamatan().toLowerCase();
                    if (namapemilih.contains(newText)){
                        mynewList.add(model);

                    }
                }
                adapter.setSearchOperation(mynewList);
                return true;
            }
        });

but how to add it in recycle adapter?

Jakir Hossain
  • 3,830
  • 1
  • 15
  • 29
rangga ario
  • 19
  • 1
  • 8
  • Define empty view. What are you trying to achieve? A simple textview, a layout with rich UI? – sanjeev Nov 07 '19 at 05:00
  • I just want to add simple textview – rangga ario Nov 07 '19 at 05:02
  • 1
    https://stackoverflow.com/questions/27414173/equivalent-of-listview-setemptyview-in-recyclerview. EmptyRecyclerview is that what you want? – Raghunandan Nov 07 '19 at 05:04
  • @ranggaario just check the adapter count and set the visibility of textview to hide or show based on it. – sanjeev Nov 07 '19 at 05:37
  • @sanjeev can you give a example? – rangga ario Nov 07 '19 at 06:41
  • 2
    Does this answer your question? [How to show an empty view with a RecyclerView?](https://stackoverflow.com/questions/28217436/how-to-show-an-empty-view-with-a-recyclerview) – Sharp Edge Nov 07 '19 at 06:43
  • you just need to add the textview in your recyclerview activity and setVisibility gone when no data in recylerview and set Visible when data is avaiable in recyclerview – rachna Nov 07 '19 at 07:22
  • 1
    @SharpEdge's link should answer your question.. I am voting this question as duplicate as it will be easier for future visitors.. – sanjeev Nov 07 '19 at 07:25

1 Answers1

0
     search_bill.setOnQueryTextListener( new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String s) {
   return false;
                }
     @Override
                public boolean onQueryTextChange(String newText){
    if (newText.length()>0) {
                         int search = Integer.parseInt( (newText));
                            modelList = helper.SearchBill(search );
                            bill_adapter = new Bill_Adapter(getApplicationContext(), modelList );
                            recyclerView.setAdapter( bill_adapter );
emptyView.setVisibility( View.VISIBLE )

                    }else {
                      //  Toast.makeText( Bill_List.this, "No Match found", Toast.LENGTH_LONG ).show();//
emptyView.setVisibility( View.VISIBLE )

                    }
                    return false;
                }
            });

see i have done this way, instead of toast you can use you textview.
rachna
  • 124
  • 8