Releases the focus on a view - Android User Interface

Android examples for User Interface:Touch Event

Description

Releases the focus on a view

Demo Code


//package com.java2s;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;

public class Main {
    /**//from  ww  w. j a v a2 s .  co m
     * Releases the focus on a view
     * @param view
     */
    public static void releaseFocus(View view) {
        ViewParent parent = view.getParent();
        ViewGroup group = null;
        View child = null;
        while (parent != null) {
            if (parent instanceof ViewGroup) {
                group = (ViewGroup) parent;
                for (int i = 0; i < group.getChildCount(); i++) {
                    child = group.getChildAt(i);
                    if (child != view && child.isFocusable())
                        child.requestFocus();
                }
            }
            parent = parent.getParent();
        }
    }
}

Related Tutorials