2

I have a SearchView in my app and when I type in it, every character shows up in a weird popup as can be seen below.

Example

Layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:background="@color/white"
    tools:context="com.example.myapp">

    <SearchView
        android:id="@+id/search_view"
        android:queryHint="@string/select_story_query_hint"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:divider="@color/gray"
        android:dividerHeight="1dp"/>

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/create_new_story_button"
        android:id="@+id/createStoryButton"
        android:layout_gravity="center_horizontal"
        android:layout_margin="10dp"
        android:layout_marginBottom="5dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:background="@drawable/low_priority_button_background"
        android:textColor="@color/black" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/done"
        android:id="@+id/select_story_done"
        android:layout_gravity="center_horizontal"
        android:layout_margin="10dp"
        android:layout_marginTop="5dp"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        android:background="@drawable/button_background"
        android:textColor="@color/white" />
</LinearLayout>

Code:

mSearchView = (SearchView) view.findViewById(R.id.search_view);
mSearchView.setIconifiedByDefault(false);
mSearchView.setOnQueryTextListener(this);
mSearchView.setSubmitButtonEnabled(false);
mSearchView.setQueryHint(getString(R.string.query_hint));

Listener:

@Override
public boolean onQueryTextChange(String newText) {
    if (TextUtils.isEmpty(newText)) {
        mListView.clearTextFilter();
    } else {
        mListView.setFilterText(newText);
    }
    return true;
}

I can't seem to find anything about this issue when I search (guess I am not using the correct keywords). This is also happening on multiple devices running different versions of Android (N5 with 5.1, O+O with 4.4) and only this particular field has this issue, all other EditText fields have no issue.

Mattia Maestrini
  • 32,270
  • 15
  • 87
  • 94
wislo
  • 1,110
  • 2
  • 13
  • 24
  • Is this search widget placed in ToolBar or ActionBar? If so, it could show up the menu title OR it tries to show something like an autocomplete popup. – Stan May 15 '15 at 07:32
  • @Stan Its in a fragment layout. I have update the question with the full layout code. – wislo May 15 '15 at 07:37
  • 1
    Check this; http://stackoverflow.com/questions/20278385/how-to-remove-android-searchview-popup-text-while-searching – Jonas Czech May 15 '15 at 07:41
  • It looks like a prompt of AutoCompleteEditText which, I guess, is included in SearchView itself. – Stan May 15 '15 at 07:43

1 Answers1

1

This has to do with a built in functionality of ListView's filter functionality. As JonasCz pointed out, how to solve this can be found here. My code changes to the onQueryTextChange() method to fix this (basically use the Adapter's filter functionality):

    @Override
    public boolean onQueryTextChange(String newText) {
        Filter filter = adapter.getFilter();
        if (TextUtils.isEmpty(newText)) {
            filter.filter("");
        } else {
            filter.filter(newText);
        }
        return true;
    }
Community
  • 1
  • 1
wislo
  • 1,110
  • 2
  • 13
  • 24