UPDATE:
So I tried the AssetManager way and ended up with this:
...
...
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xrp = factory.newPullParser();
AssetManager assmgr = context.getAssets();
xrp.setInput(assmgr.open("levels/level_1.xml"), null);
//Object attributes
String type = null;
int x = 0;
int y = 0;
double angleRads = 0;
int eventType = xrp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_DOCUMENT) {
} else if (eventType == XmlPullParser.START_TAG) {
if (xrp.getName().equals("Position")) {
while (!xrp.getName().equals("X")) { <----NULLPOINTER EXCEPTION HERE
eventType = xrp.next();
}
...
...
Now this code used to work fine when xrp was a XmlResourceParser but now I get this error message:
06-01 05:13:56.797: ERROR/AndroidRuntime(946): Caused by: java.lang.NullPointerException
06-01 05:13:56.797: ERROR/AndroidRuntime(946): at com.stickfigs.blockball.BlockBallView$BlockBallThread.initLevel(BlockBallView.java:342)
I don't understand why this isn't working anymore, I marked the line where the nullpointerexception is happening in the code above with an arrow.
=== vvvOLDvvv ===
In my res/xml/ folder I have a bunch of files called level_#.xml (ex: level_1.xml, level_2.xml, level_21.xml) and I have a spinner widget that I want to populate with the id names of all of the .xml files in this folder that follow the naming convention level_#.xml and only those.
I think I figured out how to set up the widget:
Spinner lsSpinner = (Spinner) findViewById(R.id.levelselect_spinner);
String levels[] = {"level_1","level_2","level_55"};
ArrayAdapter<String> spinnerArrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, levels);
spinnerArrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
lsSpinner.setAdapter(spinnerArrayAdapter);
Now I just need to generate levels[] dynamically like I explained before...
How do I go about doing this?