1

I am facing the issue in search view top search the data in realm database.I have implemented the search view and problem is how to pass the search query to the realm database to search data.

My search view implementation is

 SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    //*** setOnQueryTextFocusChangeListener ***
    searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
        }
    });

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {

            return false;
        }

        @Override
        public boolean onQueryTextChange(String searchQuery) {
            RealmDbHelper realmDbHelper = new RealmDbHelper();

            return true;
        }
    });

I have idea but i am little confused to implement that

RealmResults<RealmPhoneCallLogs> allQueryData = realm.where(RealmPhoneCallLogs.class)
            .like("number","?790*", Case.INSENSITIVE).findAll().sort("id",Sort.DESCENDING);

The above method is used to implement the searchview to search but i don't know how to pass the argument to LIKE Wildcard query.

Please help me how to query the searchview data.

Prabha Karan
  • 1,309
  • 3
  • 17
  • 35
  • I assume you need to replace the current active RealmResults with what you obtain in `onQuerytextChange`. Also, use `findAllSorted()` instead of `findAll().sort()` – EpicPandaForce May 30 '17 at 07:34
  • There is some links which may help you: https://github.com/thorbenprimke/realm-searchview/ https://news.realm.io/news/android-search-text-view/ – Dalinaum May 30 '17 at 07:40
  • @EpicPandaForce how to use the like query in realm to search the string and numeric values.My above question like query implementation is correct or not . – Prabha Karan May 30 '17 at 13:02
  • https://realm.io/docs/java/latest/api/io/realm/RealmQuery.html#like-java.lang.String-java.lang.String- – EpicPandaForce May 30 '17 at 14:21

0 Answers0