I have a set of image names in my XML file (tutor.xml).
I am trying to parse it and get my image names and set to the ImageView here in my activity.
It gives datatype error (Not applicable for image) it must be an integer.
try {
getAlphabet = getFromXML(MainActivity.this);
} catch (XmlPullParserException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
String[] str = getAlphabet.split("\n");
int lenAcAlp = str.length;
String[] textFileLink = new String[lenAcAlp];
String res = "R.drawable.";
int key=0;
while(key<lenAcAlp){
textFileLink[key] = res + str[key];
}
ImageView iv = (ImageView)findViewById(R.id.imageView1);
for(int i=0;i<lenAcAlp;i++){
iv.setImageResource(textFileLink[i]);
}
}
private String getFromXML(MainActivity mainActivity)throws XmlPullParserException, IOException {
StringBuffer stringBuffer = new StringBuffer();
Resources res = mainActivity.getResources();
XmlResourceParser xpp = res.getXml(R.xml.tutor);
xpp.next();
int eventType = xpp.getEventType();
while(eventType != XmlPullParser.END_DOCUMENT){
if(eventType == XmlPullParser.START_TAG){
if(xpp.getName().equals("tutorappdata")){
stringBuffer.append(xpp.getAttributeValue(null, "keyitem") +"\n"); }
}
eventType = xpp.next();
}
return stringBuffer.toString();
}
Please help me: how should I set my images to the ImageView iv, if not through string how shall set my images.
Thanks