arimorty / floatingsearchview

A search view that implements a floating search bar also known as persistent search
https://github.com/arimorty/floatingsearchview/blob/master/README.md
Apache License 2.0
3.54k stars 668 forks source link

Can't settext on searchview after using voice recognize speech #247

Closed wendabizcon closed 7 years ago

wendabizcon commented 7 years ago

Error message in the Logcat. requestLayout() improperly called by android.widget.RelativeLayout{4046e3c I........ ......ID 0,168-1050,1521 #7f0d01a3 app:id/search_suggestions_section} during layout: running second layout pass

mSearchView.setOnMenuItemClickListener(new FloatingSearchView.OnMenuItemClickListener() {
            @Override
            public void onActionMenuItemSelected(MenuItem item) {

                if (item.getItemId() == R.id.action_voice) {

                    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
                    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
                    startActivityForResult(intent, SPEECH_REQUEST_CODE);
                }
            }
        });
@Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {

        super.onActivityResult(requestCode, resultCode, data);

        if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {

            List<String> results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
            final String spokenText = results.get(0);

            getActivity().runOnUiThread(new Runnable() {
                public void run() {
                    mSearchView.setSearchText(spokenText);
                }
            });
        }
    }