MaterialSearchView icon indicating copy to clipboard operation
MaterialSearchView copied to clipboard

Why my project only show one suggestion?

Open TommyQuAceInfo opened this issue 8 years ago • 13 comments

<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.

TommyQuAceInfo avatar Feb 17 '17 02:02 TommyQuAceInfo

Same for me. Looks like listView can't stretch its height. Looking for fix

Tooto avatar Feb 21 '17 07:02 Tooto

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.

revolz avatar Feb 24 '17 05:02 revolz

@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.

TommyQu avatar Feb 26 '17 18:02 TommyQu

I am also facing this issue. Still no fix for this?

amzer avatar May 18 '17 07:05 amzer

@amzer No, I haven't found a solution.

TommyQu avatar May 18 '17 12:05 TommyQu

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.

dbeqiraj avatar May 23 '17 07:05 dbeqiraj

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 ;)

rana01645 avatar Jul 15 '17 13:07 rana01645

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...

facundobringas avatar Jul 19 '17 02:07 facundobringas

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

herald25santos avatar Jul 20 '17 10:07 herald25santos

How to fix ? Help me guys. Same problem. how to fix

jayson012 avatar Mar 15 '18 11:03 jayson012

anyone looking for answer ..just follow the exact ui layout and method changes as @dbeqiraj says ..thank you for your answer

SnShalitha avatar Oct 25 '18 23:10 SnShalitha

@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 avatar Aug 01 '19 17:08 ARXII-13

@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>

hungvu193 avatar Feb 26 '20 10:02 hungvu193