AsyncTask 执行完成后 ExpandableListView 未更新
我有一个 ExpandableListView,它是作为活动的一部分创建的:
@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();
}
正如您从代码中看到的,它会关闭并从 AsyncTask 中的 RSS feed 中进行拉取。
AsyncTask 完成,进度对话框消失,并且 Activity 被告知任务已完成:
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
但没有任何乐趣。
想法?
I have an ExpandableListView that is created as part of an activity:
@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();
}
as you can see from the code, it goes off and does a pull from an RSS feed in an AsyncTask.
The AsyncTask finishes, the progress dialog is dismissed and the activity is told that the task has completed:
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();
}
}
However, the ExpandableListView does not redraw/refresh itself after the data is loaded, it is a blank screen. How do you get the ExpandableListView to refresh itself with the RSS data? I have tried invalidate
and refreshDrawableState
but there was no joy.
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我猜您在下载 RSS feed 后忘记调用适配器上的
notifyDataSetChanged()
方法(可能您应该在AsyncTask
onPostExecute() 方法中调用它>)。I guess you forgot to call
notifyDataSetChanged()
method on adapter after downloading RSS feed (probably you should call it inonPostExecute()
method in yourAsyncTask
).这应该有效。
This should work.