Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Wing Chow
Wing Chow
845 Points

Trying to Add more detail to Blog reader app!

I am trying to modify the blog reader app that was taught in the blog reader app videos. For example, the current app would not be able to refresh. It makes the app unable to update any new items. To update the list view, we will have force the app close manually and reopen it again. I would like to fix this.

I would probably have to add a refresh button at the mainlistactivity, which i have to add a button in activity.main.list.xml and add some programming code in MainListActivity.java.

Secondly, i would like to add load more when user scroll down to the bottom of the list.

Dear Ben: if you could update videos with advanced function for the blog reader app. that would be awesome.

Thanks you very much!

Wing Chow
Wing Chow
845 Points

So, i was able to add a button to the main list menu, but i face difficulties when i try to figure out what codes should be added but the refresh button is clicked. here is what i wrote.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.activity_main_list, menu);
    return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int itemId = item.getItemId();

    if (itemId== R.id.action_refresh) {
        Intent intent2 = new Intent(this, GetBlogPostsTask.class);
        startActivity(intent2);
    }

    return super.onOptionsItemSelected(item);
}

However, codes i wrote makes the app stop working.

thank you very much!

2 Answers

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

Good suggestions! We talk about refreshing in the course I'm currently working on, but you're on the right track. You can't use an Intent to start an AsyncTask...you need to do it the same way you're already doing it in onCreate():

if(isNetworkAvailable()){
    mProgressBar.setVisibility(View.VISIBLE);
    GetBlogPostsTask getBlogPostsTask = new GetBlogPostsTask();
    getBlogPostsTask.execute();
}
else{
    Toast.makeText(this, "Network is unavailable!", Toast.LENGTH_LONG).show();
}

Further, since you'll be doing that code in two places, you could create a method to run this code and just call it from both places.

As for loading the list as you scroll to the bottom--that's a bit more complex. Here's one place to start researching that idea: http://stackoverflow.com/questions/1080811/android-endless-list

Wing Chow
Wing Chow
845 Points

Thank you very much Ben! I am really looking forward to the refreshing of the course. I am really hoping for the customlistview, which allow us to see a thumbnail in the mainlistview. I think that would make the blog reader app more comprehensive.

Again, thank you very much for your hardwork!