4

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?

1
  • Doh! <Beats head on desk while lamenting that will not get last two hours of life back.> The magical answer is notifyDataSetChanged() on the Adapter class. May 24, 2011 at 20:07

2 Answers 2

3

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).

1

This should work.

newsListAdapter.notifyDataSetChanged()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.