Thanks. I need images, so.... I have problems with array... (images)

xml

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android";>
<stage id="@drawable/level1" android:drawable="@drawable/level1"
android:layout_width="fill_parent" />
<items>
<item id="@drawable/it1" android:drawable="@drawable/it1"
android:layout_width="fill_parent"/>
<item id="@drawable/it2" android:drawable="@drawable/it2"
android:layout_width="fill_parent"/>
</items>
</resources>

java

public class main extends Activity {
/** Called when the activity is first created. */
private static final String TAG = "CompXML";
int[] items;
Canvas canvas = new Canvas();
Paint paint = new Paint();


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TextView tv = new TextView(this);
ImageView iv = new ImageView(this);
ImageView item = new ImageView(this);

RelativeLayout myLayout = new RelativeLayout(this);

try
{
XmlResourceParser xrp = this.getResources().getXml(R.xml.game);

while (xrp.getEventType() != XmlResourceParser.END_DOCUMENT) {
if (xrp.getEventType() == XmlResourceParser.START_TAG) {

//s - tag name
String s = xrp.getName();

if (s.equals("stage")) {

int resid = xrp.getAttributeResourceValue(null, "id", 0);

Bitmap viewStage = BitmapFactory.decodeResource(this.getResources(),
resid);
iv.setImageBitmap(viewStage);

myLayout.addView(iv);




} else if (s.equals("item")) {


for(int i=0; i<xrp.getAttributeCount(); i++) {
int resid = xrp.getAttributeResourceValue(null, "id", 0);
Bitmap viewItems = BitmapFactory.decodeResource(this.getResources(),
resid);
item.setImageBitmap(viewItems);
myLayout.addView(item);


}

}

} else if (xrp.getEventType() == XmlResourceParser.END_TAG) {
;
} else if (xrp.getEventType() == XmlResourceParser.TEXT) {

String s1 = xrp.getText();
tv.append(s1 + "\n\n");
}
xrp.next();
}
xrp.close();

} catch (XmlPullParserException xppe) {
Log.e(TAG, "Failure of .getEventType or .next, probably bad file
format");
xppe.toString();
} catch (IOException ioe) {
Log.e(TAG, "Unable to read resource file");
ioe.printStackTrace();
}

setContentView(myLayout);
}

}

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to