Example usage for android.view View getId

List of usage examples for android.view View getId

Introduction

In this page you can find the example usage for android.view View getId.

Prototype

@IdRes
@ViewDebug.CapturedViewProperty
public int getId() 

Source Link

Document

Returns this view's identifier.

Usage

From source file:Main.java

public static int getRelativeLeft(View myView) {
    if (myView.getId() == android.R.id.content)
        return myView.getLeft();
    else//from www. j  a va 2  s  .c o  m
        return myView.getLeft() + getRelativeLeft((View) myView.getParent());
}

From source file:Main.java

/**
 * Methods used for the slider//  w w  w . j a va 2  s .  c o  m
 */

public static int getRelativeTop(View myView) {
    if (myView.getId() == android.R.id.content)
        return myView.getTop();
    else
        return myView.getTop() + getRelativeTop((View) myView.getParent());
}

From source file:Main.java

public static String getIDNameFromView(View v) {
    // -- get your View --
    int id = v.getId(); // get integer id of view
    String idString = "";
    if (id != View.NO_ID) { // make sure id is valid
        Resources res = v.getResources(); // get resources
        if (res != null)
            idString = res.getResourceEntryName(id); // get id string entry
    }//  w  ww.  ja  v  a  2 s .  c o  m
    return idString;
}

From source file:Main.java

public static View findParentViewById(View view, int id) {
    ViewParent viewParent = view.getParent();

    while (viewParent != null && viewParent instanceof View) {
        View parentView = (View) viewParent;
        if (parentView.getId() == id)
            return parentView;

        viewParent = parentView.getParent();
    }/* w w  w .  ja  v  a  2 s.c o m*/

    return null;
}

From source file:Main.java

public static View findParentView(View view, int parentId) {
    if (view == null)
        return null;
    View parent = (View) view.getParent();
    while (parent != null && parent.getId() != parentId) {
        parent = (View) parent.getParent();
    }//w ww  . j  a  v  a 2  s.co m
    return parent;
}

From source file:Main.java

public static String getIDName(View view, Class<?> clazz) {

    try {//from w w w .j a v a2 s  .  com
        Integer id = view.getId();
        Field[] ids = clazz.getFields();
        for (int i = 0; i < ids.length; i++) {
            Object val = ids[i].get(null);
            if (val != null && val instanceof Integer && ((Integer) val).intValue() == id.intValue()) {
                return ids[i].getName();
            }
        }
    } catch (Exception e) {
    }
    return "";
}

From source file:Main.java

public static String getResourceId(View v) {
    // http://stackoverflow.com/a/17583380/198348
    int id = v.getId();
    String idString = "no id";
    if (id != View.NO_ID) {
        Resources res = v.getResources();
        if (res != null)
            idString = res.getResourceEntryName(id);
    }// w  w w .j a v a2  s.  co m
    return idString;
}

From source file:Main.java

public static int getRelativeLeft(View myView) {
    //       if (myView.getParent() == myView.getRootView())
    if (myView.getId() == android.R.id.content) {
        return myView.getLeft();
    } else {/*  w  w  w .jav  a2s .com*/
        return myView.getLeft() + getRelativeLeft((View) myView.getParent());
    }
}

From source file:Main.java

public static ArrayMap<Integer, RadioButton> getRadioButtonsMap(RadioGroup radioGroup) {
    final ArrayMap<Integer, RadioButton> out = new ArrayMap<>(radioGroup.getChildCount());
    for (int i = 0; i < radioGroup.getChildCount(); i++) {
        final View v = radioGroup.getChildAt(i);
        if (v instanceof RadioButton) {
            out.put(v.getId(), (RadioButton) v);
        }/* www .  j ava 2s  .co m*/
    }
    return out;
}

From source file:edu.ucla.cens.systemlog.Analytics.java

/**
 * Log information about a view being interacted with
 * //from w w w .j a v  a2  s  .co  m
 * @param view
 * @param name Human readable name for widget
 */
public static void widget(View view, String name, String extra) {
    StringBuilder builder = new StringBuilder();
    builder.append(view.getId());
    if (name != null)
        builder.append(" ").append(name);
    else if (!TextUtils.isEmpty(view.getContentDescription()))
        builder.append(" ").append(view.getContentDescription());

    if (extra != null)
        builder.append(" [").append(extra).append("]");

    log(view.getContext(), "widget", builder);
}