Android Utililty Methods View Get

List of utility methods to do View Get


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


voidchangeViewState(View view, MotionEvent event)
change View State
if (view != null && event != null) {
    int action = event.getAction();
    if (action == MotionEvent.ACTION_DOWN) {
    } else if (action == MotionEvent.ACTION_UP
            || action == MotionEvent.ACTION_CANCEL) {
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)
try {
    String name = mContext.getResources()
    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);
if (view != null) {