I am using AsyncTask to display a progressBar when loading Rss News. Since this is my first time using asyncTask, I donโt know if my method is suitable, so please tell me if this is good for you? Its work, but I want to just be a day! Thanks.
public class BackgroundAsyncTask_nea extends AsyncTask<Void, Void, Void> { private ProgressDialog dialog; int myProgress; @Override protected void onPostExecute(Void result) { // TODO Auto-generated method stub displayRss(); dialog.dismiss(); } @Override protected void onPreExecute() { // TODO Auto-generated method stub dialog = ProgressDialog.show(nea.this, "", "Loading. Please wait...", true); myProgress = 0; } @Override protected void onProgressUpdate(Void... values) { // TODO Auto-generated method stub //super.onProgressUpdate(values); } @Override protected Void doInBackground(Void... arg0) { // TODO Auto-generated method stub loadFeed(); return null; } }
loadFeed ();
private void loadFeed(){ try{ BaseFeedParser parser = new BaseFeedParser(); messages = parser.parse(); } catch (Throwable t){ Log.e("OSFP.News",t.getMessage(),t); finish(); } }
displayRss ();
private void displayRss(){ ArrayList<HashMap<String, String>> List_nea = new ArrayList<HashMap<String, String>>(messages.size()); for (Message msg : messages){ des.add(msg.getDescription());// keimeno text.add(msg.getTitle());// titlos url.add(msg.getLink());// link imgl.add(msg.getImgLink()); HashMap<String, String> map = new HashMap<String, String>(); map.put("name", msg.getTitle()); map.put("date", msg.getDate()); List_nea.add(map); ListAdapter mSchedule = new SimpleAdapter(this, List_nea, R.layout.row, new String[] {"name", "date"}, new int[] {R.id.TextView01, R.id.TextView02}); this.setListAdapter(mSchedule); } AnimationSet set = new AnimationSet(true); Animation animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(400); set.addAnimation(animation); animation = new TranslateAnimation( Animation.RELATIVE_TO_SELF, 0.0f,Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f,Animation.RELATIVE_TO_SELF, 0.0f ); animation.setDuration(400); set.addAnimation(animation); LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f); ListView listViewn = getListView(); listViewn.setLayoutAnimation(controller); }