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

The following examples show how to use android.widget.EditText#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: EditorView.java    From Nimbus with GNU General Public License v3.0 6 votes vote down vote up
private void onBackPress(EditText editText) {
    int selection = editText.getSelectionStart();
    if (selection == 0) {
        int viewIndex = allLayout.indexOfChild(editText);
        View v = allLayout.getChildAt(viewIndex - 1);

        if (v != null) {
            if (v instanceof EditText) {
                if ((int) v.getTag() != 1) {
                    String s1 = editText.getText().toString();
                    EditText q = (EditText) v;
                    String s2 = q.getText().toString();
                    allLayout.removeView(editText);
                    q.setText(s1 + s2);
                    q.requestFocus();
                    q.setSelection(s2.length(), s2.length());
                    lastEditText = q;
                }
            } else if (v instanceof ImageView) {
                allLayout.removeView(v);
            }

        }
    }

}
 
Example 2
Source File: SlideTabsActivity.java    From GPS2SMS with GNU General Public License v3.0 6 votes vote down vote up
protected void onPrepareDialog(int id, Dialog dialog) {
    //AlertDialog aDialog = (AlertDialog) dialog;

    switch (id) {

        case DIALOG_COORD_PROPS_ID:
            try {
                EditText e1 = (EditText) dialog
                        .findViewById(R.id.mycoords_name);
                e1.requestFocus();

                DBHelper dbHelper = new DBHelper(SlideTabsActivity.this);
                RepoCoordsFragment fragment = (RepoCoordsFragment) getSupportFragmentManager().findFragmentByTag(DBHelper.getFragmentTag(R.id.viewpager, 0));
                e1.setText(dbHelper.getMyccordName(fragment.actionCoordsId));
                dbHelper.close();
                e1.selectAll();
            } catch (Exception e) {
                Log.d("gps", "EXCEPTION! " + e.toString() + " Message:" + e.getMessage());
            }

            break;

        default:
            break;
    }
}
 
Example 3
Source File: MathGameActivity.java    From cloud-cup-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    state = GameState.GAME;

    super.onCreate(savedInstanceState);
    setContentView(R.layout.math_game_activity);

    resultInput = (EditText) findViewById(R.id.result);
    resultInput.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(resultInput.getWindowToken(), 0);

            resultInput.setEnabled(false);
            resultInput.setFocusable(false);
            resultInput.setClickable(false);

            String codeValue = resultInput.getText().toString();
            gameDataRef.setValue(codeValue);
            return true;
        }
    });
    resultInput.requestFocus();

}
 
Example 4
Source File: MainActivity.java    From QueryHighlighter with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mAdapter = new CheesesAdapter();

    final ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setAdapter(mAdapter);

    final ActionBar actionBar = getSupportActionBar();
    actionBar.setCustomView(R.layout.search_view);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

    final EditText editText = (EditText) actionBar.getCustomView();
    editText.addTextChangedListener(mTextWatcher);
    editText.requestFocus();
}
 
Example 5
Source File: FormFragment.java    From shaky-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    Toolbar toolbar = (Toolbar) view.findViewById(R.id.shaky_toolbar);
    EditText messageEditText = (EditText) view.findViewById(R.id.shaky_form_message);
    ImageView attachmentImageView = (ImageView) view.findViewById(R.id.shaky_form_attachment);

    Uri screenshotUri = getArguments().getParcelable(KEY_SCREENSHOT_URI);
    int sendIconResource = getArguments().getInt(KEY_MENU);

    String title = getArguments().getString(KEY_TITLE);
    toolbar.setTitle(title);
    toolbar.setNavigationIcon(R.drawable.ic_arrow_back_white_24dp);
    toolbar.setNavigationOnClickListener(createNavigationClickListener());
    toolbar.inflateMenu(sendIconResource);
    toolbar.setOnMenuItemClickListener(createMenuClickListener(messageEditText));

    String hint = getArguments().getString(KEY_HINT);
    messageEditText.setHint(hint);
    messageEditText.requestFocus();

    attachmentImageView.setImageURI(screenshotUri);
    attachmentImageView.setOnClickListener(createNavigationClickListener());
}
 
Example 6
Source File: InputMethodUtils.java    From Simpler with Apache License 2.0 5 votes vote down vote up
/**
 * 为给定的编辑器开启软键盘
 *
 * @param editText 给定的编辑器
 */
public static void openSoftKeyboard(Context context, EditText editText) {
    editText.requestFocus();
    InputMethodManager inputMethodManager
            = (InputMethodManager) context.getSystemService(
            Context.INPUT_METHOD_SERVICE);
    inputMethodManager.showSoftInput(editText,
            InputMethodManager.SHOW_IMPLICIT);
}
 
Example 7
Source File: KeyboardUtility.java    From RippleValidatorEditText with Apache License 2.0 5 votes vote down vote up
public static void hideKeyboard(Context ct,EditText v)
{
  if(ct!=null && v!=null) {
    v.requestFocus();
    ((InputMethodManager) ct.getSystemService(ct.INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(v.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
  }
}
 
Example 8
Source File: LyricsViewFragment.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
private void startEditTagsMode() {
    ImageButton editButton = getActivity().findViewById(R.id.edit_tags_btn);
    editButton.setImageResource(R.drawable.ic_edit_anim);
    ((Animatable) editButton.getDrawable()).start();

    ((DrawerLayout) ((MainActivity) getActivity()).drawer).setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
    mRefreshLayout.setEnabled(false);
    getActivity().findViewById(R.id.refresh_fab).setEnabled(false);
    ((RefreshIcon) getActivity().findViewById(R.id.refresh_fab)).hide();
    ((Toolbar) getActivity().findViewById(R.id.toolbar)).getMenu().clear();

    ViewSwitcher viewSwitcher = getActivity().findViewById(R.id.switcher);
    EditText songTV = getActivity().findViewById(R.id.song);
    TextView artistTV = getActivity().findViewById(R.id.artist);

    EditText newLyrics = getActivity().findViewById(R.id.edit_lyrics);
    newLyrics.setTypeface(LyricsTextFactory.FontCache.get("light", getActivity()));
    newLyrics.setText(Html.fromHtml(TextUtils.isEmpty(mLyrics.getText()) ? "" : mLyrics.getText()), TextView.BufferType.EDITABLE);

    viewSwitcher.setVisibility(View.GONE);
    newLyrics.setVisibility(View.VISIBLE);

    songTV.setInputType(InputType.TYPE_CLASS_TEXT);
    artistTV.setInputType(InputType.TYPE_CLASS_TEXT);
    songTV.setBackgroundResource(R.drawable.abc_textfield_search_material);
    artistTV.setBackgroundResource(R.drawable.abc_textfield_search_material);


    if (songTV.requestFocus()) {
        InputMethodManager imm = (InputMethodManager)
                getActivity().getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.SHOW_IMPLICIT);
    }
}
 
Example 9
Source File: Pinview.java    From Pinview with MIT License 5 votes vote down vote up
/**
 * Requsets focus on current pin view and opens keyboard if forceKeyboard is enabled.
 *
 * @return the current focused pin view. It can be used to open softkeyboard manually.
 */
public View requestPinEntryFocus() {
    int      currentTag      = Math.max(0, getIndexOfCurrentFocus());
    EditText currentEditText = editTextList.get(currentTag);
    if (currentEditText != null) {
        currentEditText.requestFocus();
    }
    openKeyboard();
    return currentEditText;
}
 
Example 10
Source File: AMUtils.java    From sealtalk-android with MIT License 5 votes vote down vote up
public static void onActive(Context context, EditText et) {
    if (et == null)
        return;

    et.requestFocus();
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(et, 0);

}
 
Example 11
Source File: InputDialogFragment.java    From ChatRecyclerView with MIT License 5 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final EditText paramEditText = (EditText) view.findViewById(R.id.mEditText);
    paramEditText.requestFocus();
    paramEditText.post(new Runnable() {

        @Override
        public void run() {
            ((InputMethodManager) getActivity().getSystemService(Context
                    .INPUT_METHOD_SERVICE)).showSoftInput(paramEditText, 0);
        }
    });
}
 
Example 12
Source File: EditTextSelectionState.java    From quill with MIT License 5 votes vote down vote up
/**
 * Focus the associated EditText and restore its selection state.
 */
public void focusAndRestoreSelectionState() {
    EditText focusedEditView = this.getEditText();
    int start = this.getSelectionStart();
    int end = this.getSelectionEnd();
    final int len = focusedEditView.getText().length();
    focusedEditView.requestFocus();
    // cursor pos is == length, when it's at the very end
    if (start <= end && start >= 0 && start <= len && end >= 0 && end <= len) {
        focusedEditView.setSelection(start, end);
    } else if (end >= 0 && end <= len) {
        focusedEditView.setSelection(end);
    }
}
 
Example 13
Source File: OtherUtils.java    From LLApp with Apache License 2.0 5 votes vote down vote up
public static void initFocus(EditText editText) {
    editToEnd(editText);
    editText.setFocusable(true);
    editText.setFocusableInTouchMode(true);
    editText.requestFocus();
    editText.findFocus();
}
 
Example 14
Source File: WriteCommentFragment.java    From SteamGifts with MIT License 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View layout = inflater.inflate(R.layout.fragment_write_comment, container, false);

    setHasOptionsMenu(true);

    edit = (EditText) layout.findViewById(R.id.edit_text);
    edit.requestFocus();

    if (savedInstanceState == null && comment != null)
        edit.setText(comment.getEditableContent());

    return layout;
}
 
Example 15
Source File: ListItemExtensions.java    From Android-WYSIWYG-Editor with Apache License 2.0 5 votes vote down vote up
public void setFocusToList(View view, int position) {
    TableLayout tableLayout = (TableLayout) view;
    int count = tableLayout.getChildCount();
    if (tableLayout.getChildCount() > 0) {
        TableRow tableRow = (TableRow) tableLayout.getChildAt(position == POSITION_START ? 0 : count - 1);
        if (tableRow != null) {
            EditText editText = (EditText) tableRow.findViewById(R.id.txtText);
            if (editText.requestFocus()) {
                editText.setSelection(editText.getText().length());
            }
        }
    }
}
 
Example 16
Source File: WidgetThemeConfigActivity.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
protected static boolean validateThemeDisplayText(Context context, EditText editDisplay, boolean grabFocus )
{
    boolean isValid = true;
    editDisplay.setError(null);

    if (editDisplay.getText().toString().trim().isEmpty())
    {
        isValid = false;     // display text is empty
        editDisplay.setError(context.getString(R.string.edittheme_error_displaytext));
        if (grabFocus)
            editDisplay.requestFocus();
    }
    return isValid;
}
 
Example 17
Source File: BufferFragment.java    From tapchat-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick() {
    final EditText editText = (EditText) getView().findViewById(R.id.text_entry);
    editText.requestFocus();
    editText.setText(String.format("%s: %s", getObject(), editText.getText()));
    editText.setSelection(editText.getText().length());
}
 
Example 18
Source File: SpinnerDialog.java    From SearchableSpinner with Apache License 2.0 5 votes vote down vote up
private void showKeyboard(final EditText ettext) {
    ettext.requestFocus();
    ettext.postDelayed(new Runnable() {
                           @Override
                           public void run() {
                               InputMethodManager keyboard = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
                               keyboard.showSoftInput(ettext, 0);
                           }
                       }
            , 200);
}
 
Example 19
Source File: Pinview.java    From Pinview with MIT License 4 votes vote down vote up
/**
 * A method to take care of all the initialisations.
 *
 * @param context
 * @param attrs
 * @param defStyleAttr
 */
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    this.removeAllViews();
    mPinHeight *= DENSITY;
    mPinWidth *= DENSITY;
    mSplitWidth *= DENSITY;
    setWillNotDraw(false);
    initAttributes(context, attrs, defStyleAttr);
    params = new LayoutParams(mPinWidth, mPinHeight);
    setOrientation(HORIZONTAL);
    createEditTexts();
    super.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean focused = false;
            for (EditText editText : editTextList) {
                if (editText.length() == 0) {
                    editText.requestFocus();
                    openKeyboard();
                    focused = true;
                    break;
                }
            }
            if (!focused && editTextList.size() > 0) { // Focus the last view
                editTextList.get(editTextList.size() - 1).requestFocus();
            }
            if (mClickListener != null) {
                mClickListener.onClick(Pinview.this);
            }
        }
    });
    // Bring up the keyboard
    final View firstEditText = editTextList.get(0);
    if (firstEditText != null)
        firstEditText.postDelayed(new Runnable() {
            @Override
            public void run() {
                openKeyboard();
            }
        }, 200);
    updateEnabledState();
}
 
Example 20
Source File: KeyboardUtils.java    From volume_control_android with MIT License 4 votes vote down vote up
public static void showKeyboard(EditText mEtSearch, Context context) {
    mEtSearch.requestFocus();
    InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
    imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);
}