Example usage for android.widget SearchView setOnFocusChangeListener

List of usage examples for android.widget SearchView setOnFocusChangeListener

Introduction

In this page you can find the example usage for android.widget SearchView setOnFocusChangeListener.

Prototype

public void setOnFocusChangeListener(OnFocusChangeListener l) 

Source Link

Document

Register a callback to be invoked when focus of this view changed.

Usage

From source file:com.tweetlanes.android.core.view.BaseLaneActivity.java

void configureActionBarSearchView(Menu menu) {

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) searchItem.getActionView();

    searchItem.setShowAsActionFlags(//w  ww . jav a 2  s. c om
            MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);

    searchView.setOnQueryTextListener(this);

    OnFocusChangeListener onFocusChangeListener = new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {

            mCurrentComposeFragment.setIgnoreFocusChange(true);

            if (mComposeTweetView != null) {
                mComposeTweetView.setVisibility(View.GONE);
            }
            if (mComposeDirectMessageView != null) {
                mComposeDirectMessageView.setVisibility(View.GONE);
            }

            if (!hasFocus) {
                if (mCurrentComposeFragment == mComposeDirectMessageFragment) {
                    if (mComposeDirectMessageView != null) {
                        mComposeDirectMessageView.setVisibility(View.VISIBLE);
                    }
                } else {
                    if (mComposeTweetView != null) {
                        mComposeTweetView.setVisibility(View.VISIBLE);
                    }
                }
            }

            mCurrentComposeFragment.setIgnoreFocusChange(false);
        }

    };

    searchView.setOnQueryTextFocusChangeListener(onFocusChangeListener);
    searchView.setOnFocusChangeListener(onFocusChangeListener);
}