MaterialSearchView
MaterialSearchView copied to clipboard
Why my project only show one suggestion?
<string-array name="query_suggestions">
<item>Android</item>
<item>AOS</item>
<item>ACALA</item>
<item>Buby</item>
<item>BvaScript</item>
</string-array>
mSearchView.setSuggestions(getResources().getStringArray(R.array.query_suggestions));
When I input "A", only the first one will be shown in suggestions.
Same for me. Looks like listView can't stretch its height. Looking for fix
I face the same problem. However for some reason, the sample that comes with the code works fine with multiple suggestions which matches the search. The problem happens once I start using the library with my own code.
@Tooto @revolz I find the problem may be caused by CoordinatorLayout. I created the template by Nav Drawer layout in Android Studio. Then, in app_bar_main.xml, I got something like below:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.toe.shareyourcuisine.activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<FrameLayout
android:id="@+id/toolbar_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay"/>
<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</FrameLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
If I change CoordinatorLayout to RelativeLayout, it shows all the suggestions. However, some other layout issues have been caused.
It seems that the AppBarLayout and the content FrameLayout are overlapped by each other.
I am also facing this issue. Still no fix for this?
@amzer No, I haven't found a solution.
If you replace the CoordinatorLayout with a LinearLayout (see below), it will show all suggestions:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.toe.shareyourcuisine.activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
android:background="@android:color/transparent"
app:elevation="0dp">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColorHint="@color/colorPrimary"
android:visibility="gone"/>
</FrameLayout>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:id="@+id/content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</LinearLayout>
Also, you have to make a little change in these methods in your activity:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_details, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.action_search) {
searchView.showSearch(true);
searchView.setVisibility(View.VISIBLE);
}
return super.onOptionsItemSelected(item);
}
I said"change" because I'm supposing that your current implementation of onCreateOptionsMenu
is as @MiguelCatalan suggests in the documentation:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
MenuItem item = menu.findItem(R.id.action_search);
searchView.setMenuItem(item);
return true;
}
@amzer I hope you solve your problem with this.
I figured out a solution finally.. Which will show more than 1 suggestion with coordinate layout and appbarlayout
Place the searchview outside the CoordinatorLayout and cover the whole CoordinatorLayout with DrawerLayout.... And now it will show whole suggestion ;)
I applied a similiar workaround as @rana01645, only that I placed the SearchView outside the AppBarLayout , still inside de CoordinatorLayout. I'm not aware of the consequences of this workaround...
i found a solution if your logic came from API just remove if condition and put searchData.add(string) inside for each in SearchAdapter.
if (string.toLowerCase().startsWith(constraint.toString().toLowerCase())) { -> remove this searchData.add(string); }
there are too much filtering inside Adapter hehehe :D
How to fix ? Help me guys. Same problem. how to fix
anyone looking for answer ..just follow the exact ui layout and method changes as @dbeqiraj says ..thank you for your answer
@rana01645 's solution worked out for me. This is how my layout looks like, the MW means android:layout_width="match_parent", android:layout_height="wrap_content":
<CoordinatorLayout (MM)>
<CoordinatorLayout (MM) >
<AppBarLayout (MW)>
<Toolbar (MW)>
</Toolbar>
</AppBarLayout>
<fragment/>
</CoordinatorLayout>
<MaterialSearchView (MW) />
</CoordinatorLayout>
@ARXII-13 solution worked for me
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activities.HomeActivity">
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Theme.Tabs.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
app:popupTheme="@style/Theme.Tabs.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@drawable/ic_search_white_24dp" />
<include layout="@layout/content_home" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.miguelcatalan.materialsearchview.MaterialSearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</androidx.coordinatorlayout.widget.CoordinatorLayout>