Java Code Examples for android.widget.AutoCompleteTextView#requestFocus()

The following examples show how to use android.widget.AutoCompleteTextView#requestFocus() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DropdownMenuEndIconDelegate.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void showHideDropdown(@Nullable AutoCompleteTextView editText) {
  if (editText == null) {
    return;
  }
  if (isDropdownPopupActive()) {
    dropdownPopupDirty = false;
  }
  if (!dropdownPopupDirty) {
    if (IS_LOLLIPOP) {
      setEndIconChecked(!isEndIconChecked);
    } else {
      isEndIconChecked = !isEndIconChecked;
      endIconView.toggle();
    }
    if (isEndIconChecked) {
      editText.requestFocus();
      editText.showDropDown();
    } else {
      editText.dismissDropDown();
    }
  } else {
    dropdownPopupDirty = false;
  }
}
 
Example 2
Source File: ShowSearchFieldOnClickListener.java    From privacy-friendly-shopping-list with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onMenuItemClick(MenuItem item)
{
    TextInputLayout searchLayout = (TextInputLayout) activity.findViewById(R.id.search_input_layout);
    AutoCompleteTextView searchText = (AutoCompleteTextView) activity.findViewById(R.id.search_input_text);
    ImageButton cancel = (ImageButton) activity.findViewById(R.id.cancel_search);
    searchLayout.setVisibility(View.VISIBLE);
    cancel.setVisibility(View.VISIBLE);
    if ( searchText.requestFocus() )
    {
        showKeyboard();
    }
    AutoCompleteTextView searchAutoCompleteTextView = (AutoCompleteTextView) activity.findViewById(R.id.search_input_text);
    searchAutoCompleteTextView.setText(StringUtils.EMPTY);
    return true;
}
 
Example 3
Source File: MaterialDialog.java    From DialogUtil with Apache License 2.0 6 votes vote down vote up
public void setContentView(View contentView) {
    ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    contentView.setLayoutParams(layoutParams);
    if (contentView instanceof ListView) {
        setListViewHeightBasedOnChildren((ListView) contentView);
    }
    LinearLayout linearLayout = (LinearLayout) mAlertDialogWindow.findViewById(
            R.id.message_content_view);
    if (linearLayout != null) {
        linearLayout.removeAllViews();
        linearLayout.addView(contentView);
    }
    for (int i = 0; i < (linearLayout != null ? linearLayout.getChildCount() : 0); i++) {
        if (linearLayout.getChildAt(i) instanceof AutoCompleteTextView) {
            AutoCompleteTextView autoCompleteTextView
                    = (AutoCompleteTextView) linearLayout.getChildAt(i);
            autoCompleteTextView.setFocusable(true);
            autoCompleteTextView.requestFocus();
            autoCompleteTextView.setFocusableInTouchMode(true);
        }
    }
}
 
Example 4
Source File: EditHeadingFragment.java    From mOrgAnd with GNU General Public License v2.0 6 votes vote down vote up
@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;
}
 
Example 5
Source File: MaterialDialog.java    From pius1 with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void setContentView(View contentView)
{
           ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
	ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
           contentView.setLayoutParams(layoutParams);
           if (contentView instanceof ListView)
    {
               setListViewHeightBasedOnChildren((ListView) contentView);
           }
           LinearLayout linearLayout = (LinearLayout) mAlertDialogWindow.findViewById(
	R.id.message_content_view);
           if (linearLayout != null)
    {
               linearLayout.removeAllViews();
               linearLayout.addView(contentView);
           }
           for (int i = 0; i < (linearLayout != null ? linearLayout.getChildCount() : 0); i++)
    {
               if (linearLayout.getChildAt(i) instanceof AutoCompleteTextView)
	{
                   AutoCompleteTextView autoCompleteTextView
		= (AutoCompleteTextView) linearLayout.getChildAt(i);
                   autoCompleteTextView.setFocusable(true);
                   autoCompleteTextView.requestFocus();
                   autoCompleteTextView.setFocusableInTouchMode(true);
               }
           }
       }
 
Example 6
Source File: Main.java    From iZhihu with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean onMenuItemActionExpand(MenuItem menuItem) {
    mAutoCompleteTextView = (AutoCompleteTextView) menuItem.getActionView().findViewById(R.id.search);

    questionsAdapter = new QuestionsAdapter(this, searchedQuestions);
    questionsAdapter.setHideDescription(true); // Hide Description

    mAutoCompleteTextView.addTextChangedListener(textWatcher);
    mAutoCompleteTextView.setAdapter(questionsAdapter);
    mAutoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            Helper.startDetailActivity(Main.this, searchedQuestions, i);
        }
    });

    // Request focus.
    mAutoCompleteTextView.requestFocus();
    (new Timer()).schedule(
            new TimerTask() {
                @Override
                public void run() {
                    mInputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                }
            }, 10
    );
    return true;
}
 
Example 7
Source File: MaterialDialog.java    From pius1 with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void setView(View view)
{
           LinearLayout l = (LinearLayout) mAlertDialogWindow.findViewById(R.id.contentView);
           l.removeAllViews();
           ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
	ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
           view.setLayoutParams(layoutParams);

           view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
	    @Override public void onFocusChange(View v, boolean hasFocus)
	    {
		mAlertDialogWindow.setSoftInputMode(
                           WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
		// show imm
		InputMethodManager imm = (InputMethodManager) mContext.getSystemService(
                           Context.INPUT_METHOD_SERVICE);
		imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
				    InputMethodManager.HIDE_IMPLICIT_ONLY);
	    }
	});

           l.addView(view);

           if (view instanceof ViewGroup)
    {

               ViewGroup viewGroup = (ViewGroup) view;

               for (int i = 0; i < viewGroup.getChildCount(); i++)
	{
                   if (viewGroup.getChildAt(i) instanceof EditText)
	    {
                       EditText editText = (EditText) viewGroup.getChildAt(i);
                       editText.setFocusable(true);
                       editText.requestFocus();
                       editText.setFocusableInTouchMode(true);
                   }
               }
               for (int i = 0; i < viewGroup.getChildCount(); i++)
	{
                   if (viewGroup.getChildAt(i) instanceof AutoCompleteTextView)
	    {
                       AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) viewGroup
		    .getChildAt(i);
                       autoCompleteTextView.setFocusable(true);
                       autoCompleteTextView.requestFocus();
                       autoCompleteTextView.setFocusableInTouchMode(true);
                   }
               }
           }
       }
 
Example 8
Source File: TechnicolorFragment.java    From upcKeygen with GNU General Public License v2.0 4 votes vote down vote up
@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;
}
 
Example 9
Source File: MaterialDialog.java    From DialogUtil with Apache License 2.0 4 votes vote down vote up
public void setView(View view) {
    LinearLayout l = (LinearLayout) mAlertDialogWindow.findViewById(R.id.contentView);
    l.removeAllViews();
    ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    view.setLayoutParams(layoutParams);

    view.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override public void onFocusChange(View v, boolean hasFocus) {
            mAlertDialogWindow.setSoftInputMode(
                    WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
            // show imm
            InputMethodManager imm = (InputMethodManager) mContext.getSystemService(
                    Context.INPUT_METHOD_SERVICE);
            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,
                    InputMethodManager.HIDE_IMPLICIT_ONLY);
        }
    });

    l.addView(view);

    if (view instanceof ViewGroup) {

        ViewGroup viewGroup = (ViewGroup) view;

        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            if (viewGroup.getChildAt(i) instanceof EditText) {
                EditText editText = (EditText) viewGroup.getChildAt(i);
                editText.setFocusable(true);
                editText.requestFocus();
                editText.setFocusableInTouchMode(true);
            }
        }
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            if (viewGroup.getChildAt(i) instanceof AutoCompleteTextView) {
                AutoCompleteTextView autoCompleteTextView = (AutoCompleteTextView) viewGroup
                        .getChildAt(i);
                autoCompleteTextView.setFocusable(true);
                autoCompleteTextView.requestFocus();
                autoCompleteTextView.setFocusableInTouchMode(true);
            }
        }
    }
}