我的菜单选项按钮位于与提取HTTP数据的类不同的类中。它会给我一个“PhotoGalleryFragment不是封闭类”的错误。
我该如何修复这样的问题?谢谢。
new PhotoGalleryFragment.FetchItemsTask("top-rated").execute();
PhotoGalleryActivity.java - 在这里,我试图让"最受欢迎的电影"按钮被按下时,将"top-rated"参数传递给FetchItemsTask来运行,并更改API网址和将返回的JSON从"popular"更改为"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 - 在这里,我正在尝试获取数据。
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();
}
}
我该如何修复这样的问题?谢谢。