Seachview search fragment data

Asked

Viewed 40 times

0

In the application has Toolbar and 2 tabs through the Tablayout with 1 fragment in each tab.

I want to put the Materialsearchview library to implement the searchview that will be done by searching the recyclerview items that is in TAB Phones .

But I put Materialsearchview in activity_main.xml

<com.mancj.materialsearchbar.MaterialSearchBar
    style="@style/MaterialSearchBarLight"
    app:mt_speechMode="false"
    app:mt_hint="Pesquisar telefones"
    app:mt_maxSuggestionsCount="10"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/searchBar" />

When I try to use Materialsearchbar for the null point Exception fragment.

I have to put Materialsearchbar in the xml of Fragment or have some way to use in Activity xml?

inserir a descrição da imagem aqui

1 answer

0

I was able to solve leaving Materialsearchbar in actionbar’s xml and put it in the fragment like this.

Before

materialSearchBar = (MaterialSearchBar) view.findViewById(R.id.searchBar);

I switched to

materialSearchBar = (MaterialSearchBar) getActivity().findViewById(R.id.searchBar);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.