Example usage for android.content.res XmlResourceParser getAttributeResourceValue

List of usage examples for android.content.res XmlResourceParser getAttributeResourceValue

Introduction

In this page you can find the example usage for android.content.res XmlResourceParser getAttributeResourceValue.

Prototype

public int getAttributeResourceValue(String namespace, String attribute, int defaultValue);

Source Link

Document

Return the value of 'attribute' as a resource identifier.

Usage

From source file:com.CrestronXPanelApp.CrestronXPanelApp.java

/**
 * Creates the fragments by parsing the layouts xml document
 */// w  ww . j  av a 2s.c om
public void initializeFragments() {
    XmlResourceParser xr = getResources().getXml(R.xml.layouts);
    int eventType = XmlPullParser.END_DOCUMENT;
    try {
        eventType = xr.getEventType();
    } catch (XmlPullParserException e) {
        throw new RuntimeException("Cannot parse the layouts file, no way to show");
    }
    while (eventType != XmlPullParser.END_DOCUMENT) {
        if (eventType == XmlPullParser.START_TAG && xr.getName().equals("item")) {
            int layout = xr.getAttributeResourceValue(null, "layout", 0);
            String name = xr.getAttributeValue(null, "title");
            mFragments.add(new FragEntry(AppFragment.newInstance(layout), name));
        }
        try {
            eventType = xr.next();
        } catch (Exception e) {
            break; // TODO better handling here
        }
    }
}