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! While you're at it, check out some resources Treehouse students have shared here.
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 trialWing Chow
845 PointsCodes for Refresh button goes wrong!
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, when i press the refresh button. The app quit.
thank you very much!
1 Answer
Wing Chow
845 PointsOMG, it so simple! the answer has always been there! here is the solution:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int itemId = item.getItemId();
if (itemId== R.id.action_refresh) {
mProgressBar.setVisibility(View.VISIBLE);
GetBlogPostsTask r_getBlogPostsTask = new GetBlogPostsTask();
r_getBlogPostsTask.execute();
}
return super.onOptionsItemSelected(item);
}
Wing Chow
845 PointsWing Chow
845 PointsI have make some modification and now it does refresh but it brings up another mainlistactivity every single time when i press it.