setThreshold ( )源码实例Demo

android.widget.AutoCompleteTextView#setThreshold ( )源码实例Demo

下面列出了android.widget.AutoCompleteTextView#setThreshold ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: browser   文件: BrowserActivity.java
/**
 * method to generate search suggestions for the AutoCompleteTextView from
 * previously searched URLs
 */
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) {

		}

	});

	getUrl.setSelectAllOnFocus(true);
	mSearchAdapter = new SearchAdapter(mActivity, mDarkTheme, isIncognito());
	getUrl.setAdapter(mSearchAdapter);
}
 
@Override
public void onEditTextAttached(@NonNull TextInputLayout textInputLayout) {
  AutoCompleteTextView autoCompleteTextView =
      castAutoCompleteTextViewOrThrow(textInputLayout.getEditText());

  setPopupBackground(autoCompleteTextView);
  addRippleEffect(autoCompleteTextView);
  setUpDropdownShowHideBehavior(autoCompleteTextView);
  autoCompleteTextView.setThreshold(0);
  autoCompleteTextView.removeTextChangedListener(exposedDropdownEndIconTextWatcher);
  autoCompleteTextView.addTextChangedListener(exposedDropdownEndIconTextWatcher);
  textInputLayout.setEndIconCheckable(true);
  textInputLayout.setErrorIconDrawable(null);
  textInputLayout.setTextInputAccessibilityDelegate(accessibilityDelegate);

  textInputLayout.setEndIconVisible(true);
}
 
源代码3 项目: BotLibre   文件: CreateBotActivity.java
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void onCreate(Bundle savedInstanceState) {
       super.onCreate(savedInstanceState);
       setContentView(R.layout.activity_create_bot);
       
       resetView();
       
       final AutoCompleteTextView templateText = (AutoCompleteTextView) findViewById(R.id.templateText);
       templateText.setText(MainActivity.template);
       ArrayAdapter adapter = new ArrayAdapter(this,
               android.R.layout.select_dialog_item, MainActivity.getAllTemplates(this));
       templateText.setThreshold(0);
       templateText.setAdapter(adapter);
       templateText.setOnTouchListener(new View.OnTouchListener() {
    	   @Override
    	   public boolean onTouch(View v, MotionEvent event){
    		   templateText.showDropDown();
    		   return false;
    	   }
    	});
}
 
源代码4 项目: mOrgAnd   文件: EditHeadingFragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.edit_heading_fragment, container, false);

    tagsView = (AutoCompleteTextView) view.findViewById(R.id.tags);
    inheritedTagsView = (TextView) view.findViewById(R.id.inheritedTags);

    headingView = (AutoCompleteTextView) view.findViewById(R.id.heading);
    headingView.setOnEditorActionListener(this);
    headingView.setThreshold(0);
    headingView.requestFocus();
    getDialog().getWindow().setSoftInputMode(
            WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);

    return view;
}
 
源代码5 项目: OpenHub   文件: SearchActivity.java
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_search, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView =
            (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(this);
    searchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
    searchView.setQuery(mPresenter.getSearchModels().get(0).getQuery(), false);
    if (isInputMode) {
        MenuItemCompat.expandActionView(searchItem);
    } else {
        MenuItemCompat.collapseActionView(searchItem);
    }
    MenuItemCompat.setOnActionExpandListener(searchItem, this);

    AutoCompleteTextView autoCompleteTextView = searchView
            .findViewById(android.support.v7.appcompat.R.id.search_src_text);
    autoCompleteTextView.setThreshold(0);
    autoCompleteTextView.setAdapter(new ArrayAdapter<>(this,
            R.layout.layout_item_simple_list, mPresenter.getSearchRecordList()));
    autoCompleteTextView.setDropDownBackgroundDrawable(new ColorDrawable(ViewUtils.getWindowBackground(getActivity())));
    autoCompleteTextView.setOnItemClickListener((parent, view, position, id) -> {
        onQueryTextSubmit(parent.getAdapter().getItem(position).toString());
    });

    return super.onCreateOptionsMenu(menu);
}
 
源代码6 项目: EosCommander   文件: UiUtils.java
public static void setupAccountHistory( AutoCompleteTextView... autoTextViewArray ) {
    for ( AutoCompleteTextView actv : autoTextViewArray ) {
        AccountAdapter adapter = new AccountAdapter(actv.getContext(), R.layout.account_suggestion, R.id.eos_account);
        if (actv instanceof MultiAutoCompleteTextView) {
            ((MultiAutoCompleteTextView) actv).setTokenizer(new WhitSpaceTokenizer());
        }
        actv.setThreshold(1);
        actv.setAdapter(adapter);
    }
}
 
源代码7 项目: Xndroid   文件: BrowserActivity.java
/**
 * method to generate search suggestions for the AutoCompleteTextView from
 * previously searched URLs
 */
private void initializeSearchSuggestions(final AutoCompleteTextView getUrl) {

    mSuggestionsAdapter = new SuggestionsAdapter(this, mDarkTheme, isIncognito());

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

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
            String url = null;
            CharSequence urlString = ((TextView) view.findViewById(R.id.url)).getText();
            if (urlString != null) {
                url = urlString.toString();
            }
            if (url == null || url.startsWith(getString(R.string.suggestion))) {
                CharSequence searchString = ((TextView) view.findViewById(R.id.title)).getText();
                if (searchString != null) {
                    url = searchString.toString();
                }
            }
            if (url == null) {
                return;
            }
            getUrl.setText(url);
            searchTheWeb(url);
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0);
            mPresenter.onAutoCompleteItemPressed();
        }

    });

    getUrl.setSelectAllOnFocus(true);
    getUrl.setAdapter(mSuggestionsAdapter);
}
 
源代码8 项目: MDPreference   文件: ViewUtil.java
/**
 * Apply any AutoCompleteTextView style attributes to a view.
 * @param v
 * @param attrs
 * @param defStyleAttr
 * @param defStyleRes
 */
private static void applyStyle(AutoCompleteTextView v,  AttributeSet attrs, int defStyleAttr, int defStyleRes){
    TypedArray a = v.getContext().obtainStyledAttributes(attrs, R.styleable.AutoCompleteTextView, defStyleAttr, defStyleRes);

    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);

        if(attr == R.styleable.AutoCompleteTextView_android_completionHint)
            v.setCompletionHint(a.getString(attr));
        else if(attr == R.styleable.AutoCompleteTextView_android_completionThreshold)
            v.setThreshold(a.getInteger(attr, 0));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownAnchor)
            v.setDropDownAnchor(a.getResourceId(attr, 0));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownHeight)
            v.setDropDownHeight(a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownWidth)
            v.setDropDownWidth(a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownHorizontalOffset)
            v.setDropDownHorizontalOffset(a.getDimensionPixelSize(attr, 0));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownVerticalOffset)
            v.setDropDownVerticalOffset(a.getDimensionPixelSize(attr, 0));
        else if(attr == R.styleable.AutoCompleteTextView_android_popupBackground)
            v.setDropDownBackgroundDrawable(a.getDrawable(attr));
    }
    a.recycle();
}
 
源代码9 项目: journaldev   文件: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Creating the instance of ArrayAdapter containing list of fruit names
    ArrayAdapter<String> adapter = new ArrayAdapter<String>
            (this, android.R.layout.select_dialog_item, fruits);
    //Getting the instance of AutoCompleteTextView
    AutoCompleteTextView actv = (AutoCompleteTextView) findViewById(R.id.autoCompleteTextView);
    actv.setThreshold(1);//will start working from first character
    actv.setAdapter(adapter);//setting the adapter data into the AutoCompleteTextView
    actv.setTextColor(Color.RED);

}
 
源代码10 项目: JumpGo   文件: BrowserActivity.java
/**
 * method to generate search suggestions for the AutoCompleteTextView from
 * previously searched URLs
 */
private void initializeSearchSuggestions(final AutoCompleteTextView getUrl) {

    mSuggestionsAdapter = new SuggestionsAdapter(this, mDarkTheme, isIncognito());

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

        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
            String url = null;
            CharSequence urlString = ((TextView) view.findViewById(R.id.url)).getText();
            if (urlString != null) {
                url = urlString.toString();
            }
            if (url == null || url.startsWith(getString(R.string.suggestion))) {
                CharSequence searchString = ((TextView) view.findViewById(R.id.title)).getText();
                if (searchString != null) {
                    url = searchString.toString();
                }
            }
            if (url == null) {
                return;
            }
            getUrl.setText(url);
            searchTheWeb(url);
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(getUrl.getWindowToken(), 0);
            mPresenter.onAutoCompleteItemPressed();
        }

    });

    getUrl.setSelectAllOnFocus(true);
    getUrl.setAdapter(mSuggestionsAdapter);
}
 
源代码11 项目: material   文件: ViewUtil.java
/**
 * Apply any AutoCompleteTextView style attributes to a view.
 * @param v
 * @param attrs
 * @param defStyleAttr
 * @param defStyleRes
 */
private static void applyStyle(AutoCompleteTextView v,  AttributeSet attrs, int defStyleAttr, int defStyleRes){
    TypedArray a = v.getContext().obtainStyledAttributes(attrs, R.styleable.AutoCompleteTextView, defStyleAttr, defStyleRes);

    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);

        if(attr == R.styleable.AutoCompleteTextView_android_completionHint)
            v.setCompletionHint(a.getString(attr));
        else if(attr == R.styleable.AutoCompleteTextView_android_completionThreshold)
            v.setThreshold(a.getInteger(attr, 0));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownAnchor)
            v.setDropDownAnchor(a.getResourceId(attr, 0));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownHeight)
            v.setDropDownHeight(a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownWidth)
            v.setDropDownWidth(a.getLayoutDimension(attr, ViewGroup.LayoutParams.WRAP_CONTENT));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownHorizontalOffset)
            v.setDropDownHorizontalOffset(a.getDimensionPixelSize(attr, 0));
        else if(attr == R.styleable.AutoCompleteTextView_android_dropDownVerticalOffset)
            v.setDropDownVerticalOffset(a.getDimensionPixelSize(attr, 0));
        else if(attr == R.styleable.AutoCompleteTextView_android_popupBackground)
            v.setDropDownBackgroundDrawable(a.getDrawable(attr));
    }
    a.recycle();
}
 
@Override
protected void afterLayoutInflated(Context context, AttributeSet attrs, int defStyle) {
    super.afterLayoutInflated(context, attrs, defStyle);

    final CharSequence completionHint;
    final int completionThreshold;
    final int popupBackground;
    final int dropDownWidth;
    final int dropDownHeight;

    if (attrs == null) {
        completionHint = "";
        completionThreshold = 1;
        dropDownHeight = ViewGroup.LayoutParams.WRAP_CONTENT;
        dropDownWidth = ViewGroup.LayoutParams.WRAP_CONTENT;
        popupBackground = getDefaultPopupBackgroundResId();
    } else {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatingLabelAutoCompleteTextView, defStyle, 0);
        completionHint = a.getText(R.styleable.FloatingLabelAutoCompleteTextView_android_completionHint);
        completionThreshold = a.getInt(R.styleable.FloatingLabelAutoCompleteTextView_android_completionThreshold, 1);
        dropDownHeight = a.getDimensionPixelSize(R.styleable.FloatingLabelAutoCompleteTextView_android_dropDownHeight, ViewGroup.LayoutParams.WRAP_CONTENT);
        dropDownWidth = a.getDimensionPixelSize(R.styleable.FloatingLabelAutoCompleteTextView_android_dropDownWidth, ViewGroup.LayoutParams.WRAP_CONTENT);
        popupBackground = a.getResourceId(R.styleable.FloatingLabelAutoCompleteTextView_android_popupBackground, getDefaultPopupBackgroundResId());
        a.recycle();
    }

    final AutoCompleteTextView inputWidget = getInputWidget();
    inputWidget.setCompletionHint(completionHint);
    inputWidget.setThreshold(completionThreshold);
    inputWidget.setDropDownWidth(dropDownWidth);
    inputWidget.setDropDownHeight(dropDownHeight);
    inputWidget.setDropDownBackgroundResource(popupBackground);
    inputWidget.addTextChangedListener(new EditTextWatcher());
}
 
private void setupAutoComplete(AutoCompleteTextView autoCompleteTextView) {
    Set<String> tagValues = OSMDataSet.tagValues();
    String[] tagValuesArr = tagValues.toArray(new String[tagValues.size()]);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(this.getActivity(),
            android.R.layout.simple_dropdown_item_1line, tagValuesArr);
    autoCompleteTextView.setAdapter(adapter);
    autoCompleteTextView.setThreshold(1);
}
 
private void setupAutoComplete(AutoCompleteTextView autoCompleteTextView) {
    Set<String> tagValues = OSMDataSet.tagValues();
    String[] tagValuesArr = tagValues.toArray(new String[tagValues.size()]);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(this.getActivity(),
            android.R.layout.simple_dropdown_item_1line, tagValuesArr);
    autoCompleteTextView.setAdapter(adapter);
    autoCompleteTextView.setThreshold(1);
}
 
源代码15 项目: Android-Remote   文件: ConnectActivity.java
private void initializeUi() {
    setSupportActionBar((Toolbar) findViewById(R.id.toolbar));

    // Get the Layoutelements
    mBtnConnect = (Button) findViewById(R.id.btnConnect);
    mBtnConnect.setOnClickListener(oclConnect);
    mBtnConnect.requestFocus();

    mBtnClementine = (ImageButton) findViewById(R.id.btnClementineIcon);
    mBtnClementine.setOnClickListener(oclClementine);

    // Setup the animation for the Clementine icon
    mAlphaDown = new AlphaAnimation(1.0f, 0.3f);
    mAlphaUp = new AlphaAnimation(0.3f, 1.0f);
    mAlphaDown.setDuration(ANIMATION_DURATION);
    mAlphaUp.setDuration(ANIMATION_DURATION);
    mAlphaDown.setFillAfter(true);
    mAlphaUp.setFillAfter(true);
    mAlphaUp.setAnimationListener(mAnimationListener);
    mAlphaDown.setAnimationListener(mAnimationListener);
    mAnimationCancel = false;

    // Ip and Autoconnect
    mEtIp = (AutoCompleteTextView) findViewById(R.id.etIp);
    mEtIp.setRawInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    mEtIp.setThreshold(3);

    // Get old ip and auto-connect from shared prefences
    mEtIp.setText(mSharedPref.getString(SharedPreferencesKeys.SP_KEY_IP, ""));
    mEtIp.setSelection(mEtIp.length());

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.select_dialog_item, mKnownIps.toArray(new String[0]));
    mEtIp.setAdapter(adapter);

    // Get the last auth code
    mAuthCode = mSharedPref.getInt(SharedPreferencesKeys.SP_LAST_AUTH_CODE, 0);
}
 
源代码16 项目: codeexamples-android   文件: MainActivity.java
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    AutoCompleteTextView view = (AutoCompleteTextView) findViewById(R.id.autoComplete);
    String[] androidversion = getResources().
            getStringArray(R.array.android_versoins);
    ArrayAdapter<String> adapter =
            new ArrayAdapter<String>
                    (this,R.layout.row_layout,
                            R.id.textView,
                            androidversion);
    view.setThreshold(1);
    view.setAdapter(adapter);
}
 
源代码17 项目: upcKeygen   文件: TechnicolorFragment.java
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_technicolor, container, false);

    loading = view.findViewById(R.id.loading_spinner);
    mainView = view.findViewById(R.id.main_view);
    final CheckBox freq24 = (CheckBox) view.findViewById(R.id.radio_24);
    final CheckBox freq5 = (CheckBox) view.findViewById(R.id.radio_5);
    final AutoCompleteTextView edit = (AutoCompleteTextView) view
            .findViewById(R.id.manual_autotext);

    final String[] routers = getResources().getStringArray(
            R.array.supported_routers);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(getActivity(),
            android.R.layout.simple_dropdown_item_1line, routers);

    edit.setAdapter(adapter);
    edit.setThreshold(1);
    edit.requestFocus();

    final InputFilter filterSSID = new InputFilter() {
        public CharSequence filter(CharSequence source, int start, int end,
                                   Spanned dest, int dstart, int dend) {
            for (int i = start; i < end; i++) {
                if (!Character.isLetterOrDigit(source.charAt(i))
                        && source.charAt(i) != '-'
                        && source.charAt(i) != '_'
                        && source.charAt(i) != ' ') {
                    return "";
                }
            }
            return null;
        }
    };
    final InputFilter lengthFilter = new InputFilter.LengthFilter(8); //Filter to 10 characters
    edit.setFilters(new InputFilter[]{filterSSID, lengthFilter});
    edit.setImeOptions(EditorInfo.IME_ACTION_DONE);

    Button calc = (Button) view.findViewById(R.id.bt_calc);
    calc.setOnClickListener(new View.OnClickListener() {

        @TargetApi(Build.VERSION_CODES.HONEYCOMB)
        public void onClick(View v) {
            String ssid = "UPC" + edit.getText().toString().trim();
            if (!freq24.isChecked() && !freq5.isChecked()) {
                freq24.setChecked(true);
                freq5.setChecked(true);
            }

            int mode = (freq24.isChecked() ? 1 : 0) | (freq5.isChecked() ? 2 : 0);
            KeygenMatcherTask matcher = new KeygenMatcherTask(ssid, mode);
            if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
                matcher.execute();
            } else {
                matcher.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
            }

        }
    });

    return view;
}