您好 我加載鳴叫從用戶帳戶列表視圖顯示。現在我想讓用戶知道他們在等待的過程中發生了什麼。我已經實現了異步任務,但由於某種原因,onPostExcecute從未被調用。這就是爲什麼對話不會被刪除。異步任務進度對話框不會消失
有人可以給我一個提示。什麼我做錯了?
,如果這是需要
我可以張貼我的TweetAdapterClass這是我的AsyncClass
public class ProgressTask extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
dialog.setTitle("Even geduld...");
dialog.setMessage("De tweets worden ingeladen...");
dialog.show();
}
protected void onPostExecute() {
try {
if (dialog.isShowing()) {
adaptor = new TweetListAdaptor(MainActivity.this, R.layout.tweetitem, loadTweets());
setListAdapter(adaptor);
dialog.dismiss();
}
} catch (Exception e) {
}
}
@Override
protected Void doInBackground(Void... arg0) {
return null;
}
}
LoadTweets看起來是這樣的:
private ArrayList<Tweets> loadTweets() {
ArrayList<Tweets> tweets = new ArrayList<Tweets>();
try {
HttpClient hc = new DefaultHttpClient();
HttpGet get = new HttpGet(
"http://search.twitter.com/search.json?q=JobXXL_be&rpp=10");
// HttpGet get = new
// HttpGet("http://search.twitter.com/search.json?q=Stijn_messiaen&rp=10");
HttpResponse rp = hc.execute(get);
if (rp.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
String result = EntityUtils.toString(rp.getEntity());
JSONObject root = new JSONObject(result);
JSONArray sessions = root.getJSONArray("results");
for (int i = 0; i < sessions.length(); i++) {
JSONObject session = sessions.getJSONObject(i);
Tweets tweet = new Tweets();
tweet.setTweet(session.getString("text"));
tweet.setUser(session.getString("from_user"));
// datum vertalen
String date = session.getString("created_at").substring(5,
16);
String[] arrDate = date.split(" ");
int id = this.getResources().getIdentifier(
arrDate[1].toString(), "string",
this.getPackageName());
String maand = getResources().getString(id);
date = arrDate[0].toString() + " " + maand + " "
+ arrDate[2].toString();
tweet.setDate(date);
tweets.add(tweet);
}
}
} catch (Exception e) {
Log.e("TwitterFeedActivity", "Error loading JSON", e);
}
return tweets;
}
編輯:我將我的LoadTweets()在我的doInBackgroundMethod
這解決了我的問題!
什麼是您的loadTweets()方法是什麼樣子? – 2011-05-24 12:36:17
@ nicholas.hauschild我已經添加了代碼 – Hannelore 2011-05-24 12:40:45