MaterialSearchView icon indicating copy to clipboard operation
MaterialSearchView copied to clipboard

i want dispaly full array without filter

Open enggazzar opened this issue 8 years ago • 10 comments

i want display full array values without filter becuas datafrom webservice

enggazzar avatar Jun 04 '16 18:06 enggazzar

Did you find any solution? Please reply me

oalpayli avatar Jun 16 '16 13:06 oalpayli

i found solution in my case what your case may be can help but i didnot use this library or anothere library

enggazzar avatar Jun 20 '16 09:06 enggazzar

for (int i = 0; i < item.size(); i++) { sug[i] = item.get(i).getSnippet().getTitle(); matrixCursor.addRow(new Object[]{i, item.get(i).getSnippet().getTitle()});

    }

    adapter =
            new SimpleCursorAdapter(getApplicationContext(), R.layout.autocompletemy, matrixCursor, new String[]{"item"}, new int[]{R.id.tttt});
    searchView.setSuggestionsAdapter(adapter);

enggazzar avatar Jun 20 '16 10:06 enggazzar

wish this help and you are welcome for any quistion

enggazzar avatar Jun 20 '16 10:06 enggazzar

@enggazzar can you please explain how you achieved this?

rajeevjaiswal avatar Oct 27 '16 12:10 rajeevjaiswal

@enggazzar @oalpayli import the project as gradle module , then in SearchAdapter.java line 58 replace if (string.toLowerCase().startsWith(constraint.toString().toLowerCase())) with if (string.toLowerCase().contains(constraint.toString().toLowerCase()))

Thats it. It will show all suggestion. If you want to hide suggestion on touch of searchview then in MaterialSearchView.java in line 198 mSearchSrcTextView.setOnFocusChangeListener(new OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { showKeyboard(mSearchSrcTextView); // showSuggestions(); // comment this } } });

rajeevjaiswal avatar Oct 27 '16 13:10 rajeevjaiswal

first declare 1- private SearchView searchView = null; private SearchView.OnQueryTextListener queryTextListener;

MatrixCursor matrixCursor;
SimpleCursorAdapter adapter;
String[] sug;
String[] columns = new String[]{"_id", "item"};

2-------------------------- @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); MenuItem searchItem = menu.findItem(R.id.action_search); // searchItem.setTitle("search pages"); // searchItem.setTitleCondensed("test"); SearchManager searchManager = (SearchManager) FbSearchPageList.this.getSystemService(Context.SEARCH_SERVICE);

    searchView = null;
    if (searchItem != null) {
        searchView = (SearchView) searchItem.getActionView();
        searchView.setFocusable(true);
        searchView.setIconified(false);
        searchView.setQueryHint(getString(R.string.hint_search_fb_page));

        // searchView.setQuery("kkk", false);

// String[] columns = new String[] { "_id", "item", "description" }; // // MatrixCursor matrixCursor= new MatrixCursor(columns); // startManagingCursor(matrixCursor); // // matrixCursor.addRow(new Object[]{1, "Item A", "...."}); // matrixCursor.addRow(new Object[]{2, "Item b", "...."}); // // SimpleCursorAdapter adapter = // new SimpleCursorAdapter(this, R.layout.autocompletemy, matrixCursor, new String [] {"item"}, new int[] {R.id.tttt}); // } if (searchView != null) { searchView.setOnSuggestionListener(this); searchView.setSearchableInfo(searchManager.getSearchableInfo(FbSearchPageList.this.getComponentName())); // searchView.setSuggestionsAdapter(adapter); queryTextListener = new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextChange(String newText) { Log.i("onQueryTextChange", newText);

                if (newText.length() == 2 || newText.length() == 6 || newText.length() == 9 || newText.length() == 12 || newText.length() == 15) {
                    //  if(newText.length()==2){


                    matrixCursor = new MatrixCursor(columns);
                    startManagingCursor(matrixCursor);

                    getSugesstion(newText);

                    //
                    // searchView.setOnSuggestionListener(this);
                    // matrixCursor.addRow(new Object[]{1, "Item A"});
                    // matrixCursor.addRow(new Object[]{2, "Item b"});

                    //  adapter.notifyDataSetChanged();


                }


                return true;
            }

            @Override
            public boolean onQueryTextSubmit(String query) {
                nextLink = "";
                Log.i("onQueryTextSubmit", query);
                ///  hideKeyBoard();
                //  searchView.setIconified(true);
                mRecycler.requestFocus();
                getFbData(query);


                // rq.cancel(true);

                return true;
            }
        };
        searchView.setOnQueryTextListener(queryTextListener);
    }
    // searchItem.setTitle("lol");
    return true;
}

private void getSugesstion(String query) {
    GraphRequest request = GraphRequest.newGraphPathRequest(
            AccessToken.getCurrentAccessToken(),
            "/search",
            new GraphRequest.Callback() {
                @Override
                public void onCompleted(GraphResponse response) {

// String resp = null; try {

                        JSONArray rawPhotosData = response.getJSONObject().getJSONArray("data");

// sug = new String[rawPhotosData.length()]; for (int j = 0; j < rawPhotosData.length(); j++) {

                            JSONObject json_data = rawPhotosData.getJSONObject(j);
                            sug[j] = json_data.getString("name");
                            matrixCursor.addRow(new Object[]{j, json_data.getString("name")});

                        }


                        adapter =
                                new SimpleCursorAdapter(getApplicationContext(), R.layout.autocompletemy, matrixCursor, new String[]{"item"}, new int[]{R.id.tttt});
                        searchView.setSuggestionsAdapter(adapter);


                    } catch (JSONException e) {

                        Toast.makeText(getApplicationContext(), getString(R.string.pologize), Toast.LENGTH_LONG).show();
                        e.printStackTrace();
                    } catch (Exception e) {
                        Toast.makeText(getApplicationContext(), getString(R.string.pologize), Toast.LENGTH_LONG).show();
                        e.printStackTrace();
                    }
                }
            });

enggazzar avatar Dec 26 '16 14:12 enggazzar

i know its late, maybe it would be useful for others.

the other way is adding the library classes instead of using gradle. after adding library classes you can change getFilter() method inside SearchAdapter.

change @Override performFiltering method here to this:

protected FilterResults performFiltering(CharSequence constraint) { FilterResults filterResults = new FilterResults(); if (!TextUtils.isEmpty(constraint)) { List<String> searchData = new ArrayList<>(); searchData.addAll(Arrays.asList(suggestions)); filterResults.values = searchData; filterResults.count = searchData.size(); } return filterResults; }

SetareMaghari avatar Dec 30 '17 06:12 SetareMaghari

@SetareMaghari thank you! by the way you don't need to add library classes to your project, you can use gradle as usual. In this case you may create your own SearchAdapter class, then copy code of the library's class, change what you want and add it to the view with .setAdapter method

mSearchView.setAdapter(
        new FullListSearchAdapter(this, suggestions.toArray(new String[suggestions.size()])));

tinkooladik avatar Mar 20 '18 19:03 tinkooladik

In my case when the search query is empty I show the whole list of suggestions and when user enters something, suggestions are filtering

@Override protected FilterResults performFiltering(CharSequence constraint) {
        FilterResults filterResults = new FilterResults();
        // Retrieve the autocomplete results.
        List<String> searchData = new ArrayList<>();

        for (String string : suggestions) {
          if (TextUtils.isEmpty(constraint) || string.toLowerCase()
              .startsWith(constraint.toString().toLowerCase())) {
            searchData.add(string);
          }
        }

        // Assign the data to the FilterResults
        filterResults.values = searchData;
        filterResults.count = searchData.size();
        return filterResults;
      }

tinkooladik avatar Mar 20 '18 19:03 tinkooladik