My menu option button is in a different class than the class that fetches HTTP data. And it's giving me "PhotoGalleryFragment is not an enclosing class" error for
new PhotoGalleryFragment.FetchItemsTask("top-rated").execute();
PhotoGalleryActivity.java - In here, I am trying to make it so when the "Top Rated Movie" button is pressed, it passes the "top-rated" argument for the FetchItemsTask to run and change the API url and change the returned JSON from "popular" to "top-rated"
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.topRatedMovies) {
Toast.makeText(getApplicationContext(), "Top Rated Movie selected", Toast.LENGTH_LONG).show();
new PhotoGalleryFragment.FetchItemsTask("top-rated").execute();
return true;
}
return super.onOptionsItemSelected(item);
}
PhotoGalleryFragment.java - In here, I'm trying to fetch the data.
public class FetchItemsTask extends AsyncTask<Void,Void,List<MovieItem>> {
private String mQuery;
public FetchItemsTask(String query) {
mQuery = query;
}
@Override
protected List<MovieItem> doInBackground(Void... params) {
return new MovieFetchr().fetchItems(mQuery);
}
@Override
protected void onPostExecute(List<MovieItem> items) {
mItems = items;
for (int i = 0; i < mItems.size(); i++) {
}
setupAdapter();
}
}
How would I fix something like this? Thanks.