View requestFocus - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for View requestFocus method.

This code example shows how to use the following methods:findViewById, isFocused, requestFocus, setOnFocusChangeListener
    /** 
     * @param editViewId must be EditView 
     */ 
    public void requestFocusAndShowKeyboard(int editViewId) {
        // Set Focus to password View. 
        final View viewToBeFocused = mView.findViewById(editViewId);
        if (viewToBeFocused == null) {
            Log.w(TAG, "password field to be focused not found.");
        } else if (!(viewToBeFocused instanceof EditText)) {
            Log.w(TAG, "password field is not EditText");
        } else { 
            if (viewToBeFocused.isFocused()) {
                Log.i(TAG, "Already focused");
                if (!mInputMethodManager.showSoftInput(viewToBeFocused, 0)) {
                    Log.w(TAG, "Failed to show SoftInput");
                } 
            } else { 
                // After acquiring the focus, we show software keyboard. 
                viewToBeFocused.setOnFocusChangeListener(this);
                final boolean requestFocusResult = viewToBeFocused.requestFocus();

8
CodeRank
This code example shows how to use the following methods:requestFocus, setOnTouchListener, getSettings, loadUrl, setWebViewClient
		} 
 
		final LoginUIOperationCallback externalCallback = callback;
		final AlertDialog.Builder builder = new AlertDialog.Builder(context);
		// Create the Web View to show the login page 
		final WebView wv = new WebView(context);
		builder.setTitle("Connecting to a service");
		builder.setCancelable(true);
		builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
 
			@Override 
			public void onCancel(DialogInterface dialog) {
				if (externalCallback != null) {
					externalCallback.onCompleted(null,
							new MobileServiceException("User Canceled")); 
				} 
			} 
		}); 
 
		// Set cancel button's action 

7
CodeRank
This code example shows how to use the following methods:requestFocus
        mImm.hideSoftInputFromWindow(editText.getWindowToken(), 0);
 
        // Bring the target EditText into focus. 
        mTargetActivity.runOnUiThread(new Runnable() {
            public void run() { 
                editText.requestFocus();
            } 
        }); 
 
        // Get the original location of the EditText. 
        editText.getLocationOnScreen(origLocation);
 
        // Tap the EditText to bring up the IME. 
        sendKeys(KeyEvent.KEYCODE_DPAD_CENTER);
 
        // Wait until the EditText pops above the IME or until we hit the timeout. 
        editText.getLocationOnScreen(newLocation);
        long timeoutTime = SystemClock.uptimeMillis() + WAIT_FOR_IME;
        while (newLocation[1] > rootViewHeight - IME_MIN_HEIGHT && SystemClock.uptimeMillis() < timeoutTime) {
            editText.getLocationOnScreen(newLocation);
7
CodeRank
This code example shows how to use the following methods:requestFocus, setFocusableInTouchMode, setText
This code example shows how to use the following methods:requestFocus, setFocusable, setFocusableInTouchMode, setId, setLayoutParams
    public boolean actionIdentifierUp = false;
    public boolean actionIdentifierDown = false;
 
    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        View layout = new LinearLayout(this);
        layout.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        layout.setId(CONTENT_VIEW_ID);
 
        layout.setOnKeyListener(new OnKeyListener() {
 
            @Override 
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                keyIdentifier = keyCode;
 
                if (event.getAction() == KeyEvent.ACTION_DOWN)
                    actionIdentifierDown = true;
                else if (event.getAction() == KeyEvent.ACTION_UP)
                    actionIdentifierUp = true;
                return true; 

7
CodeRank
This code example shows how to use the following methods:getContext, requestFocus
	 * @return true if the keyboard could be shown, false otherwise. 
	 */ 
	public static boolean showKeyboardFor(View view)
	{ 
		InputMethodManager manager = (InputMethodManager)
		view.getContext( ).getSystemService( Context.INPUT_METHOD_SERVICE );
		if( null == manager )
		{ 
			return false; 
		} 
		 
		view.requestFocus( );
		manager.showSoftInput( view, InputMethodManager.SHOW_FORCED );
		 
		return true; 
	} 
	 
	/** 
	 * Hides the keyboard from the given view. If the view is 
	 * not assigned to a window, this request is ignored. 
7
CodeRank
This code example shows how to use the following methods:hasFocus, requestFocus
        assertTrue(root.hasFocus());
    } 
 
    @Test 
    public void clearFocus_shouldRecursivelyClearTheFocusOfAllChildren() throws Exception { 
        child3a.requestFocus();
 
        root.clearFocus();
 
        assertFalse(child3a.hasFocus());
        assertFalse(child3.hasFocus());
        assertFalse(root.hasFocus());
 
        root.requestFocus();
        root.clearFocus();
        assertFalse(root.hasFocus());
    } 
 
    @Test 
    public void dump_shouldDumpStructure() throws Exception { 
6
CodeRank
This code example shows how to use the following methods:requestFocus, setOnFocusChangeListener, setHint, setInputType, setText
            mHint = object.optString("hint");
            mAutofocus = object.optBoolean("autofocus");
        } 
 
        public View getView(final Context context) throws UnsupportedOperationException {
            EditText input = new EditText(context);
            input.setInputType(InputType.TYPE_CLASS_TEXT);
            input.setText(mValue);
 
            if (!TextUtils.isEmpty(mHint)) {
                input.setHint(mHint);
            } 
 
            if (mAutofocus) {
                input.setOnFocusChangeListener(new View.OnFocusChangeListener() {
                    @Override 
                    public void onFocusChange(View v, boolean hasFocus) {
                        if (hasFocus) {
                            ((InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(v, 0);
                        } 

8
CodeRank
This code example shows how to use the following methods:requestFocus, setVisibility, loadUrl
This code example shows how to use the following methods:requestFocus, selectAll
        setResult(RESULT_OK, new Intent(mDur.getText().toString()));
        finish();
    } 
 
    private void notifyUser(int msgId) {
        mDur.requestFocus();
        mDur.selectAll();
        Toast.makeText(this, msgId, Toast.LENGTH_SHORT).show();
        return; 
    } 
} 
7
CodeRank

Related View requestFocus Questions & Answers:

requestFocus Method Overview
Call this to try to give focus to a specific view or to one of its descendants and give it hints about the direction and a specific rectangle that the focus is coming from.
See Code Examples for other Android View Methods: