Example usage for android.widget AutoCompleteTextView setDropDownWidth

List of usage examples for android.widget AutoCompleteTextView setDropDownWidth

Introduction

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

Prototype

public void setDropDownWidth(int width) 

Source Link

Document

Sets the current width for the auto-complete drop down list.

Usage

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

/**
 * method to generate search suggestions for the AutoCompleteTextView from
 * previously searched URLs//from   w w w . ja  v  a 2s  .co m
 */
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);
}