Android Utililty Methods View Get

List of utility methods to do View Get

Description

The list of methods to do View Get are organized into topic(s).

Method

voidchangeViewState(View view, MotionEvent event)
change View State
if (view != null && event != null) {
    int action = event.getAction();
    if (action == MotionEvent.ACTION_DOWN) {
        view.setPressed(true);
    } else if (action == MotionEvent.ACTION_UP
            || action == MotionEvent.ACTION_CANCEL) {
        view.setPressed(false);
ViewParentfindInParents(View view, Class parentClass)
find In Parents
ViewParent par = view.getParent();
while (par != null) {
    if (parentClass.isAssignableFrom(par.getClass()))
        return par;
    par = par.getParent();
return null;
TfindUsingTag(View v, int resourceId)
find Using Tag
Object result = v.getTag(resourceId);
if (result == null) {
    result = (T) v.findViewById(resourceId);
    v.setTag(resourceId, result);
return (T) result;
intgetRandomView(int size)
get Random View
Random rd = new Random();
int randomInt = rd.nextInt(size);
return randomInt;
Stringgetname(Context mContext, View v)
getname
try {
    String name = mContext.getResources()
            .getResourceName(v.getId());
    return name;
} catch (Exception ex) {
    return "";
voidforceChildrenInvalidateRecursively(View view)
force Children Invalidate Recursively
if (view instanceof ViewGroup) {
    ViewGroup childGroup = (ViewGroup) view;
    int childCnt = childGroup.getChildCount();
    for (int i = 0; i < childCnt; i++) {
        View childView = childGroup.getChildAt(i);
        forceChildrenInvalidateRecursively(childView);
if (view != null) {
    view.invalidate();