I am using ArrayList in onPostExecute(AsyncTask) on Fragment.
The problem is that arrivalInfoArrayList
is empty after I executed AsyncTask.
I tried to use
1)
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
//Code for the UiThread
}
});
2)
new Handler().post(new Runnable() {
@Override
public void run() {
}
});
But it did not work. How can I solve this? This is my code.
arrivalAsync = new ArrivalAsync() {
@Override
protected void onPostExecute(String arrivalUrl) {
try {
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(new StringReader(arrivalUrl));
int eventType = xpp.getEventType();
while(eventType != XmlPullParser.END_DOCUMENT) {
if(eventType == XmlPullParser.START_DOCUMENT) {
} else if(eventType == XmlPullParser.START_TAG) {
String tagName = xpp.getName();
switch (tagName) {
case "arsId":
bl_arsId = true;
break;
case "firstTm":
bl_firstTm = true;
break;
case "lastTm":
bl_lastTm = true;
case "stNm":
bl_stNm = true;
break;
}
} else if(eventType == XmlPullParser.TEXT) {
if(bl_arsId) {
arsId = xpp.getText();
arrivalInfo.setArsId(arsId);
bl_arsId = false;
}
if(bl_firstTm) {
firstTm = xpp.getText();
arrivalInfo.setFirstTm(firstTm);
bl_firstTm = false;
}
if(bl_lastTm) {
lastTm = xpp.getText();
arrivalInfo.setLastTm(lastTm);
bl_lastTm = false;
}
if(bl_stNm) {
stNm = xpp.getText();
arrivalInfo.setStNm(stNm);
bl_stNm = false;
}
} else if(eventType == XmlPullParser.END_TAG) {
String tagName = xpp.getName();
if(tagName.equals("itemList")) {
arrivalInfoArrayList.add(arrivalInfo);
arrivalInfo = new ArrivalInfo();
}
}
eventType = xpp.next();
}
} catch (Exception e) {
e.printStackTrace();
}
}
};
arrivalAsync.execute(arrivalUrl);