Example usage for android.view.inputmethod EditorInfo IME_ACTION_SEARCH

List of usage examples for android.view.inputmethod EditorInfo IME_ACTION_SEARCH

Introduction

In this page you can find the example usage for android.view.inputmethod EditorInfo IME_ACTION_SEARCH.

Prototype

int IME_ACTION_SEARCH

To view the source code for android.view.inputmethod EditorInfo IME_ACTION_SEARCH.

Click Source Link

Document

Bits of #IME_MASK_ACTION : the action key performs a "search" operation, taking the user to the results of searching for the text they have typed (in whatever context is appropriate).

Usage

From source file:com.android.example.github.ui.search.SearchFragment.java

private void initSearchInputListener() {
    binding.get().input.setOnEditorActionListener((v, actionId, event) -> {
        if (actionId == EditorInfo.IME_ACTION_SEARCH) {
            doSearch(v);//from   w ww  .j ava  2s .  com
            return true;
        }
        return false;
    });
    binding.get().input.setOnKeyListener((v, keyCode, event) -> {
        if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
            doSearch(v);
            return true;
        }
        return false;
    });
}

From source file:com.maxleapmobile.gitmaster.ui.activity.SearchActivity.java

private void initToolBar() {
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from w w w  .  jav a2s  .  c om*/
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });
    mSearchEdit = (EditText) findViewById(R.id.search);
    mSearchEdit.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH || actionId == EditorInfo.IME_ACTION_UNSPECIFIED) {
                String keyWord = mSearchEdit.getText().toString();
                if (!keyWord.isEmpty()) {
                    mKeyWord = keyWord;
                    hideSoftKeyBoard(mSearchEdit);
                    performSearch();
                }
                return true;
            }
            return false;
        }
    });
}

From source file:com.fbartnitzek.tasteemall.filter.AttributeFilterTextTabFragment.java

@Nullable
@Override//from   w  ww.j a v  a  2s  .  c  o  m
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {

    super.onCreateView(inflater, container, savedInstanceState);

    mEditFilter = (EditText) mRootView.findViewById(R.id.attribute_filter);
    mEditFilter.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            mAttributeFilter = s.toString();
            //                Log.v(LOG_TAG, "afterTextChanged, hashCode=" + this.hashCode() + ", " + "s = [" + s + "]");
            getLoaderManager().restartLoader(ATTRIBUTE_VALUES_LOADER_ID, null,
                    AttributeFilterTextTabFragment.this);
        }
    });

    mEditFilter.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            //                Log.v(LOG_TAG, "onEditorAction, hashCode=" + this.hashCode() + ", " + "v = [" + v + "], actionId = [" + actionId + "], event = [" + event + "]");
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                InputMethodManager imm = (InputMethodManager) getContext()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(mEditFilter.getWindowToken(), 0);
                return true;
            }
            return false;
        }
    });

    // focus editFilter - thx for: http://stackoverflow.com/a/26012003/5477716
    mEditFilter.requestFocus();
    InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

    mValuesRecycler = (RecyclerView) mRootView.findViewById(R.id.attribute_filter_list);
    mValuesRecycler.setLayoutManager(new LinearLayoutManager(getContext()));

    mAttributeValuesAdapter = new AttributeValuesAdapter(this);
    mValuesRecycler.setAdapter(mAttributeValuesAdapter);

    return mRootView;
}

From source file:net.olejon.mdapp.ClinicalTrialsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Input manager
    mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Layout//from   w  w w.  ja v  a 2  s. c  om
    setContentView(R.layout.activity_clinicaltrials);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.clinicaltrials_toolbar);
    toolbar.setTitle(getString(R.string.clinicaltrials_title));

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mToolbarSearchLayout = (LinearLayout) findViewById(R.id.clinicaltrials_toolbar_search_layout);
    mToolbarSearchEditText = (EditText) findViewById(R.id.clinicaltrials_toolbar_search);

    mToolbarSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0);

                search(mToolbarSearchEditText.getText().toString().trim());

                return true;
            }

            return false;
        }
    });

    ImageButton imageButton = (ImageButton) findViewById(R.id.clinicaltrials_toolbar_clear_search);

    imageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mToolbarSearchEditText.setText("");
        }
    });

    // List
    mListView = (ListView) findViewById(R.id.clinicaltrials_list);

    View listViewEmpty = findViewById(R.id.clinicaltrials_list_empty);
    mListView.setEmptyView(listViewEmpty);

    View listViewHeader = getLayoutInflater().inflate(R.layout.activity_clinicaltrials_list_subheader,
            mListView, false);
    mListView.addHeaderView(listViewHeader, null, false);

    // Floating action button
    mFloatingActionButton = (FloatingActionButton) findViewById(R.id.clinicaltrials_fab);

    mFloatingActionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mToolbarSearchLayout.getVisibility() == View.VISIBLE) {
                mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0);

                search(mToolbarSearchEditText.getText().toString().trim());
            } else {
                mToolbarSearchLayout.setVisibility(View.VISIBLE);
                mToolbarSearchEditText.requestFocus();

                mInputMethodManager.showSoftInput(mToolbarSearchEditText, 0);
            }
        }
    });
}

From source file:net.olejon.mdapp.InteractionsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Intent//ww w  .j a  v  a  2  s .co  m
    final Intent intent = getIntent();

    final String searchString = (intent.getStringExtra("search") == null) ? ""
            : intent.getStringExtra("search").split(" ")[0];

    // Input manager
    mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Layout
    setContentView(R.layout.activity_interactions);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.interactions_toolbar);
    toolbar.setTitle(getString(R.string.interactions_title));

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mToolbarSearchLayout = (LinearLayout) findViewById(R.id.interactions_toolbar_search_layout);
    mToolbarSearchEditText = (EditText) findViewById(R.id.interactions_toolbar_search);

    mToolbarSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0);

                search(mToolbarSearchEditText.getText().toString());

                return true;
            }

            return false;
        }
    });

    ImageButton imageButton = (ImageButton) findViewById(R.id.interactions_toolbar_clear_search);

    imageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mToolbarSearchEditText.setText("");
        }
    });

    if (!searchString.equals("")) {
        mToolbarSearchLayout.setVisibility(View.VISIBLE);
        mToolbarSearchEditText.setText(searchString + " ");
        mToolbarSearchEditText.setSelection(mToolbarSearchEditText.getText().length());

        mTools.showToast(getString(R.string.interactions_search_other_medications_or_substances), 1);
    }

    // List
    mListView = (ListView) findViewById(R.id.interactions_list);

    View listViewEmpty = findViewById(R.id.interactions_list_empty);
    mListView.setEmptyView(listViewEmpty);

    View listViewHeader = getLayoutInflater().inflate(R.layout.activity_interactions_list_subheader, mListView,
            false);
    mListView.addHeaderView(listViewHeader, null, false);

    // Floating action button
    mFloatingActionButton = (FloatingActionButton) findViewById(R.id.interactions_fab);

    mFloatingActionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mToolbarSearchLayout.getVisibility() == View.VISIBLE) {
                mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0);

                search(mToolbarSearchEditText.getText().toString());
            } else {
                mToolbarSearchLayout.setVisibility(View.VISIBLE);
                mToolbarSearchEditText.requestFocus();

                mInputMethodManager.showSoftInput(mToolbarSearchEditText, 0);
            }
        }
    });
}

From source file:net.olejon.mdapp.DiseasesAndTreatmentsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Input manager
    mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Layout//from   w  w  w  . j  a  va 2 s  .  c  o m
    setContentView(R.layout.activity_diseases_and_treatments);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.diseases_and_treatments_toolbar);
    toolbar.setTitle(getString(R.string.diseases_and_treatments_title));

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mToolbarSearchLayout = (LinearLayout) findViewById(R.id.diseases_and_treatments_toolbar_search_layout);
    mToolbarSearchEditText = (EditText) findViewById(R.id.diseases_and_treatments_toolbar_search);

    mToolbarSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0);

                search(mToolbarSearchEditText.getText().toString().trim());

                return true;
            }

            return false;
        }
    });

    final ImageButton toolbarSearchClearButton = (ImageButton) findViewById(
            R.id.diseases_and_treatments_toolbar_clear_search);

    toolbarSearchClearButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mToolbarSearchEditText.setText("");
        }
    });

    // List
    mListView = (ListView) findViewById(R.id.diseases_and_treatments_list);

    View listViewEmpty = findViewById(R.id.diseases_and_treatments_list_empty);
    mListView.setEmptyView(listViewEmpty);

    View listViewHeader = getLayoutInflater().inflate(R.layout.activity_diseases_and_treatments_list_subheader,
            mListView, false);
    mListView.addHeaderView(listViewHeader, null, false);

    // Floating action buttons
    mFloatingActionButton = (FloatingActionButton) findViewById(R.id.diseases_and_treatments_fab);

    mFloatingActionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            String string = mToolbarSearchEditText.getText().toString().trim();

            if (mToolbarSearchLayout.getVisibility() == View.VISIBLE && !string.equals("")) {
                search(string);
            } else {
                showSearchLanguageDialog();
            }
        }
    });
}

From source file:dat255.grupp06.bibbla.fragments.SearchFragment.java

 @Override
public void onActivityCreated(Bundle savedInstanceState) {
   super.onActivityCreated(savedInstanceState);
      /*from   w w w. j ava 2s  .  co  m*/
   // Get our GUI elements.
   searchButton = (Button)getSherlockActivity().findViewById(R.id.button_search);
   searchEdit = (EditText)getSherlockActivity().findViewById(R.id.edit_search);
      
   searchEdit.setTextColor(0xfff0641e);

   searchProgress = (ProgressBar)getSherlockActivity().findViewById(R.id.progress_search);
      
   // Create a listener for keyboard "enter" button.
   OnEditorActionListener listener = new OnEditorActionListener() {
       public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
           if (actionId == EditorInfo.IME_ACTION_SEARCH) {
              // Simulate click on the search button.
               searchButton.performClick();
               return true;
           }
           return false;
       }
   };
   // Add our newly created listener to the text field.
   searchEdit.setOnEditorActionListener(listener);
}

From source file:net.olejon.mdapp.PoisoningsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Intent/*from  www. j ava 2 s  .co  m*/
    final Intent intent = getIntent();

    final String searchString = intent.getStringExtra("search");

    // Input manager
    mInputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

    // Layout
    setContentView(R.layout.activity_poisonings);

    // Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.poisonings_toolbar);
    toolbar.setTitle(getString(R.string.poisonings_title));

    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    mToolbarSearchLayout = (LinearLayout) findViewById(R.id.poisonings_toolbar_search_layout);
    mToolbarSearchEditText = (EditText) findViewById(R.id.poisonings_toolbar_search);

    mToolbarSearchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_SEARCH || keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0);

                search(mToolbarSearchEditText.getText().toString().trim());

                return true;
            }

            return false;
        }
    });

    ImageButton imageButton = (ImageButton) findViewById(R.id.poisonings_toolbar_clear_search);

    imageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            mToolbarSearchEditText.setText("");
        }
    });

    // Floating action button
    mFloatingActionButton = (FloatingActionButton) findViewById(R.id.poisonings_fab);

    mFloatingActionButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mToolbarSearchLayout.getVisibility() == View.VISIBLE) {
                mInputMethodManager.hideSoftInputFromWindow(mToolbarSearchEditText.getWindowToken(), 0);

                search(mToolbarSearchEditText.getText().toString().trim());
            } else {
                mToolbarSearchLayout.setVisibility(View.VISIBLE);
                mToolbarSearchEditText.requestFocus();

                mInputMethodManager.showSoftInput(mToolbarSearchEditText, 0);
            }
        }
    });

    // List
    mListView = (ListView) findViewById(R.id.poisonings_list);

    View listViewEmpty = findViewById(R.id.poisonings_list_empty);
    mListView.setEmptyView(listViewEmpty);

    View listViewHeader = getLayoutInflater().inflate(R.layout.activity_poisonings_list_subheader, mListView,
            false);
    mListView.addHeaderView(listViewHeader, null, false);

    // Search
    if (searchString != null)
        search(searchString.split(" ")[0]);
}

From source file:com.doctorapp.doctorappclient.basic.ui.fragment.CaseHistoryFragment.java

private void init() {
    systemApplcation = (SystemApplcation) getActivity().getApplication();

    //?//from   w w  w .  j a v a 2  s. co m
    search_iv_delete = (ImageView) rootView.findViewById(R.id.search_iv_delete);
    search_iv_delete.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            search_et_input.setText("");
            search_iv_delete.setVisibility(View.GONE);
        }
    });

    //?Edittext
    search_et_input = (EditText) rootView.findViewById(R.id.search_et_input);
    search_et_input.addTextChangedListener(new EditChangedListener());
    search_et_input.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                notifyStartSearching(search_et_input.getText().toString());
            }
            return true;
        }
    });

    listView = (GridView) rootView.findViewById(R.id.dept_listView);
    listView.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //
            PatientsListFragment newFragment = new PatientsListFragment(depts_temp.get(position).getDEPTCODE(),
                    depts_temp.get(position).getDEPTNAME());
            systemApplcation.setPatientListFragment(newFragment);
            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.replace(R.id.mainFrameLayout, newFragment);
            transaction.addToBackStack(null);
            transaction.commit();
        }
    });

    SystemApplcation applcation = (SystemApplcation) getActivity().getApplication();
    DOCINVHISInLoginSrvOutputItem dict = applcation.getStaffDict();
    hashMap.put("DOC_NAME", dict != null ? dict.getUSERNAME() : "");
    queryData(hashMap);
}

From source file:com.dm.material.dashboard.candybar.fragments.IconsSearchFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu_icons_search, menu);
    MenuItem search = menu.findItem(R.id.menu_search);

    mSearchView = (SearchView) MenuItemCompat.getActionView(search);
    mSearchView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_SEARCH);
    mSearchView.setQueryHint(getActivity().getResources().getString(R.string.search_icon));
    mSearchView.setMaxWidth(Integer.MAX_VALUE);

    MenuItemCompat.expandActionView(search);
    mSearchView.setIconifiedByDefault(false);
    mSearchView.clearFocus();//from  w ww  .  j a  va 2  s  .c  o  m

    int color = ColorHelper.getAttributeColor(getActivity(), R.attr.toolbar_icon);
    ViewHelper.changeSearchViewTextColor(mSearchView, color, ColorHelper.setColorAlpha(color, 0.6f));
    View view = mSearchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
    if (view != null)
        view.setBackgroundColor(Color.TRANSPARENT);

    ImageView closeIcon = (ImageView) mSearchView
            .findViewById(android.support.v7.appcompat.R.id.search_close_btn);
    if (closeIcon != null)
        closeIcon.setImageResource(R.drawable.ic_toolbar_close);

    ImageView searchIcon = (ImageView) mSearchView
            .findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
    ViewHelper.removeSearchViewSearchIcon(searchIcon);

    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextChange(String string) {
            filterSearch(string);
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String string) {
            mSearchView.clearFocus();
            return true;
        }
    });
}