Issue
I try to fix it but the list data doesn't show up..also, there is some red line in my code. onPostExecute
it inform thatThe constructor SimpleAdapter(EventsActivity.syncEvent, ArrayList<HashMap<String,String>>, int, String[], int[])
is undefined.
Another thing, I would like to do is to show a progress
when we refresh the even like when we refresh notification in facebook, we will see animation of refreshing the data, last date and time we did a refresh.How can i do that? Do you have any idea? I am quite new to implementation. Thanks for your advice.
public class EventsActivity extends ListActivity {
EventDataSet sitesList = null;
ArrayList<HashMap<String, String>> mylist = new ArrayList<HashMap<String, String>>();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.listplaceholder);
}
private class syncEvent extends AsyncTask<String, Integer, String> {
@Override
protected String doInBackground(String... arg0) {
try {
/** Handling XML */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
/** Send URL to parse XML Tags */
URL sourceUrl = new URL(
"http://xxxx.heroku.com/xxxxxxxxxxx.xml");
/** Create handler to handle XML Tags ( extends DefaultHandler ) */
EventXMLHandler myXMLHandler = new EventXMLHandler();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(sourceUrl.openStream()));
} catch (Exception e) {
}
/** Get result from MyXMLHandler SitlesList Object */
sitesList = EventXMLHandler.sitesList;
/** Set the result text in textview and add it to layout */
for (int i = 0; i < sitesList.getName().size(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
map.put("name", "Name: " + sitesList.getName().get(i));
map.put("createat", "Create-At: " + Convertor.getDateTimeDDMMYY(sitesList.getCreateat().get(i)));
mylist.add(map);
}
return null;
}
@Override
protected void onPostExecute(String result) {
ListAdapter adapter = new SimpleAdapter(this, mylist, R.layout.eventitem,
new String[]{"name", "createat"},
new int[]{R.id.item_title, R.id.item_subtitle});
setListAdapter(adapter);
//super.onPostExecute(result);
}
@Override
protected void onProgressUpdate(Integer... values) {
// TODO Auto-generated method stub
super.onProgressUpdate(values);
}
}
}
Solution
The problem is with the this
reference. When you're inside the AsyncTask, this
refers to your AsyncTask subclass, and SimpleAdapter requires a Context as the first parameter. You should replace the call with an explicit reference to the parent class:
new SimpleAdapter(EventsActivity.this, mylist , R.layout.eventitem,
new String[] { "name", "createat" },
new int[] { R.id.item_title, R.id.item_subtitle });
Answered By - Shawn Lauzon
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.