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.setOnGroupClic开发者_JS百科kListener(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?
I guess you forgot to call notifyDataSetChanged()
method on adapter after downloading RSS feed (probably you should call it in onPostExecute()
method in your AsyncTask
).
This should work.
newsListAdapter.notifyDataSetChanged()
精彩评论