1

I don't understand how, but it was working fine up till yesterday... now I changed some things around and happens that, whenever I type something in the Search box of my app on the top menu, every letter I type gets deleted immediately. If I paste a longer word, its letters are quickly deleted one by one -- I can see this from a callback function on setOnQueryTextListener: the function is called every time a letter is deleted, so if I paste a word with 5 letters, ie. "Hello", the function is quickly triggered with "Hello", "Hell", "Hel", "He", "H"...and my box is left empty.

I really can't think of any reason for this to happen.

This is how I implemented it.

menu_basic.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:id="@+id/menu_basic_search"
        android:actionViewClass="com.actionbarsherlock.widget.SearchView"
        android:icon="@drawable/react_search"
        android:showAsAction="ifRoom|collapseActionView"
        android:title="@string/description_search"/>

    <item android:id="@+id/menu_basic_menu"
        android:title="@string/description_menu"
        android:icon="@drawable/react_menu"
        android:showAsAction="always" />

</menu>

on my fragment .java

    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        menu.clear();
        inflater.inflate(R.menu.menu_basic, menu);
        (getSherlockActivity()).getSupportActionBar().setHomeButtonEnabled(true);

        SearchManager searchManager = (SearchManager) getSherlockActivity().getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) menu.findItem(R.id.menu_basic_search).getActionView();
        if (null != searchView )
        {
            searchView.setSearchableInfo(searchManager.getSearchableInfo(getSherlockActivity().getComponentName()));
            searchView.setIconifiedByDefault(false);
        }

        SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() 
        {
            @Override
            public boolean onQueryTextChange(String newText) 
            {
                Log.i("SEARCH newText", newText);
                return true;
            }

            @Override
            public boolean onQueryTextSubmit(String query) 
            {
                Log.i("SEARCH query", query);
                return true;
            }
        };
        searchView.setOnQueryTextListener(queryTextListener);
    }

Apart from this, I can't find any other reference I have to the SearchView on my code.

Any idea of where the issue could be?

BkdD
  • 593
  • 1
  • 7
  • 13
  • Can you try returning `false` from the 2 methods in `queryTextListener`? – Szymon Dec 07 '13 at 10:32
  • wow, okay that's amazing... I can paste on it now without them being cleared... I still can't write though, so maybe the direct writing problem might be some focus issue? I implemented this in a fragment, and the same fragment implements TabHost. When I type something in the SearchView, the cursor disappears and the focus goes to the current tab header. – BkdD Dec 07 '13 at 10:43
  • What do you want to achieve by using `queryTextListener`? – Szymon Dec 07 '13 at 10:44
  • well I deleted a part of the code, but in onQueryTextChange I usually have a if(newText.length() > 2) { search(newText); } that sends a request to a Web Service... This web service searches the string in a database and returns me some results that i'll display. Is there a better way to perform search? :) – BkdD Dec 07 '13 at 10:48
  • You mean you want to do it for suggestions or to do the actual search? – Szymon Dec 07 '13 at 10:50
  • the actual search... at least in this case – BkdD Dec 07 '13 at 10:53

0 Answers0