我正在使用AsyncTask來加載Rss新聞時顯示progressBar。因爲這是使用的AsyncTask我不知道如果我的方法是正確的我第一次IM,所以你可以告訴我,如果它看起來不錯,你呢?它的工作,但我想只是爲了粟特!謝謝如何使用AsyncTask來顯示ProgressBar並加載Rss
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);
}
[Progressbar togther with asyncTask]的可能重複(http://stackoverflow.com/questions/4119009/progressbar-togther-with-asynctask) – Sameer