I got problems when I try to get info from XML to a string array. Is works fine if I only have one if statment withinf the: if (eventType == XmlPullParser.START_TAG) {...}
The thing is tho, I want to diffrent things to my array, both "Allergen" and "Artikelbenamning". Not sure if the problem is in the doInBackground or in the onPostExecute.
Any suggestions on what i've done wrong? The app dosen't crash it just never present the data.
protected ArrayList<String> doInBackground(String[] params) {
ArrayList<String>titles=new ArrayList<>();
try {
URL url = new URL(params[0]);
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(url.openConnection().getInputStream(), "UTF_8");
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT) {
if (eventType == XmlPullParser.START_TAG) {
if (xpp.getName().equalsIgnoreCase("Allergen")) {
titles.add(xpp.nextText());
allergen=xpp.nextText();
}
if (xpp.getName().equalsIgnoreCase("Artikelbenamning")) {
titles.add(xpp.nextText());
namn=xpp.nextText();
}
}
eventType = xpp.next();
}//end while
}//end try
catch(MalformedURLException exp){
}
catch(IOException exp){
}
catch(XmlPullParserException exp){
}
return titles;
}
protected void onPostExecute(ArrayList<String> titleResult){
ListView listView=(ListView)findViewById(R.id.listView);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(MainActivity.this,android.R.layout.simple_list_item_1,titleResult);
listView.setAdapter(adapter);
if(dialog.isShowing()){
dialog.dismiss();
}
}