Example usage for android.widget AutoCompleteTextView setDropDownAnchor

List of usage examples for android.widget AutoCompleteTextView setDropDownAnchor

Introduction

In this page you can find the example usage for android.widget AutoCompleteTextView setDropDownAnchor.

Prototype

public void setDropDownAnchor(int id) 

Source Link

Document

Sets the view to which the auto-complete drop down list should anchor.

Usage

From source file:com.dish.browser.activity.BrowserActivity.java

/**
 * method to generate search suggestions for the AutoCompleteTextView from
 * previously searched URLs//from   w ww .j a v  a  2s .c  om
 */
private void initializeSearchSuggestions(final AutoCompleteTextView getUrl) {

    getUrl.setThreshold(1);
    getUrl.setDropDownWidth(-1);
    getUrl.setDropDownAnchor(R.id.toolbar_layout);
    getUrl.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            try {
                String url;
                url = ((TextView) arg1.findViewById(R.id.url)).getText().toString();
                if (url.startsWith(mActivity.getString(R.string.suggestion))) {
                    url = ((TextView) arg1.findViewById(R.id.title)).getText().toString();
                } else {
                    getUrl.setText(url);
                }
                searchTheWeb(url);
                InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0);
                if (mCurrentView != null) {
                    mCurrentView.requestFocus();
                }
            } catch (NullPointerException e) {
                Log.e("Browser Error: ", "NullPointerException on item click");
            }
        }

    });

    getUrl.setSelectAllOnFocus(true);
    mSearchAdapter = new SearchAdapter(mActivity, mDarkTheme, isIncognito());
    getUrl.setAdapter(mSearchAdapter);
}