之後我有一個作爲活動的一部分,創造了一個ExpandableListView:ExpandableListView未更新的AsyncTask執行完畢
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.news);
// create the exandable list view widget
newsListAdapter = new NewsListAdapter(this.getApplicationContext());
newsListView = (ExpandableListView) findViewById(R.id.news_list_view);
newsListView.setAdapter(newsListAdapter);
final Button homeButton = (Button) findViewById(R.id.home_btn);
// go back to the home page
homeButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
startActivity(new Intent(view.getContext(), HomeActivity.class));
}
});
newsListView.setOnGroupClickListener(new OnGroupClickListener() {
public boolean onGroupClick(ExpandableListView parent, View view, int groupPosition, long arg3) {
return false;
}
});
newsListView.setOnChildClickListener(new OnChildClickListener() {
public boolean onChildClick(ExpandableListView parent, View view,
int groupPosition, int childPosition, long id) {
return false;
}
});
showLoadingProgressDialog();
downloadRssFeedTask = new DownloadRssFeedTask();
downloadRssFeedTask.execute();
}
,你可以從代碼中看到,它熄滅,確實從RSS拉在一個AsyncTask。
的的AsyncTask完成,進度對話框被駁回,活動被告知該任務已完成:
private void responseReceived(Channel newsResponse) {
if (newsResponse != null)
newsListAdapter.buildView(newsResponse);
}
else {
Toast toast = Toast.makeText(this.getApplicationContext(),
"There is no news available at this time.",
Toast.LENGTH_LONG);
toast.show();
}
}
然而,ExpandableListView不重繪/加載數據後刷新本身,它是一個黑屏。你如何讓ExpandableListView使用RSS數據來刷新自己?我試過invalidate
和refreshDrawableState
,但沒有歡樂。
想法?
Doh!同時感嘆不會得到最後兩個小時的生命回覆> 神奇的答案是Adapter類中的notifyDataSetChanged()。 – 2011-05-24 20:07:34