Example usage for android.widget SearchView setMaxWidth

List of usage examples for android.widget SearchView setMaxWidth

Introduction

In this page you can find the example usage for android.widget SearchView setMaxWidth.

Prototype

public void setMaxWidth(int maxpixels) 

Source Link

Document

Makes the view at most this many pixels wide

Usage

From source file:edu.ucsb.cs.cs185.inspirante.searchbyranking.SearchByRankingFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.fragment_search_by_ranking, container, false);

    final SearchView searchView = (SearchView) rootView.findViewById(R.id.search_by_ranking_search_view);
    int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
    EditText searchEditText = (EditText) searchView.findViewById(id);
    searchEditText.setTextColor(Color.GRAY);
    searchEditText.setHintTextColor(Color.GRAY);
    searchView.setOnQueryTextListener(searchViewListener);
    searchView.setMaxWidth(Integer.MAX_VALUE);
    searchView.setOnClickListener(new View.OnClickListener() {

        @Override/*from   w  w  w .j  a  v  a  2s.c  o m*/
        public void onClick(View view) {
            searchView.setFocusable(true);
            searchView.setIconified(false);
            searchView.requestFocusFromTouch();
        }
    });

    mInspireRecyclerView = (RecyclerView) rootView.findViewById(R.id.search_rv);
    mInspireRecyclerView.setHasFixedSize(true);
    mInspireRecyclerView.setNestedScrollingEnabled(false);

    frequentTags = ItemCards.getInstance(getContext()).getFrequentTags();

    mInspireAdapter = new RankByTagAdapter(getContext(), this, frequentTags);
    mInspireAdapter.setHasStableIds(true);

    mLayoutManager = new LinearLayoutManager(getContext());
    mLayoutManager.setItemPrefetchEnabled(true);

    mInspireRecyclerView.setLayoutManager(mLayoutManager);

    mInspireAdapter.setOnItemClickListener(new RankByTagAdapter.OnRecyclerViewItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            TextView tv = (TextView) view;
            Intent intent = new Intent(getActivity(), TagAndImagesActivity.class);
            intent.putExtra("TAG", tv.getText());
            startActivity(intent);
        }
    });

    ItemCards itemCards = ItemCards.getInstance(getContext());
    itemCards.setAdapter(mInspireAdapter);

    mInspireRecyclerView.setAdapter(mInspireAdapter);
    mInspireAdapter.notifyDataSetChanged();

    // Set Tag recycler view
    mTagRecyclerView = (RecyclerView) rootView.findViewById(R.id.search_tags_rv);
    mTagRecyclerView.setHasFixedSize(true);
    mTagRecyclerView.setNestedScrollingEnabled(false);
    mTagsAdapter = new TagsAdapter(getContext(), frequentTags);
    mTagsAdapter.setHasStableIds(true);
    RecyclerView.LayoutManager tagsLayoutManager = new LinearLayoutManager(getContext(),
            LinearLayoutManager.HORIZONTAL, false);
    tagsLayoutManager.setItemPrefetchEnabled(true);

    mTagRecyclerView.setLayoutManager(tagsLayoutManager);

    mTagsAdapter.setOnItemClickListener(new TagsAdapter.OnRecyclerViewItemClickListener() {
        @Override
        public void onItemClick(View view, int position) {
            String tag = mTagsAdapter.getTag(position);
            searchViewListener.onQueryTextChange(tag);
            //searchView.setFocus
            searchView.setQuery(tag, true);
            searchView.setIconified(false);
            searchView.clearFocus();
            mLayoutManager.scrollToPosition(0);

        }
    });

    mTagRecyclerView.setAdapter(mTagsAdapter);
    mTagsAdapter.notifyDataSetChanged();

    return rootView;
}