get Attribute Resource Value - Android App

Android examples for App:Resource

Description

get Attribute Resource Value

Demo Code


//package com.java2s;
import android.util.AttributeSet;

public class Main {
    public static int getAttributeResourceValue(AttributeSet attrs,
            String namespace, String attribute, int defValue) {
        int ret = defValue;

        if (attrs != null) {
            ret = attrs.getAttributeResourceValue(namespace, attribute,
                    defValue);//from  w  w w .  j  a  va  2  s . c  o  m
            if (ret == defValue) {
                int count = attrs.getAttributeCount();
                String temp = null;
                for (int i = 0; i < count; i++) {
                    temp = attrs.getAttributeName(i);
                    if (temp.equals(attribute)) {
                        ret = attrs.getAttributeResourceValue(i, defValue);
                        break;
                    }
                }
            }
        }
        return ret;
    }
}

Related Tutorials