第3引数が間違っていると言って、mainActivityにLoaderManager.LoaderCallbacksを実装しました。インターフェイスを実装するアクティビティを参照する方法は?
getSupportLoaderManager().initLoader(LOADER_ID,getUrlBundle(),this);
どうしてですか?
public class MainActivity extends AppCompatActivity implements MovieAdapter.movieAdapterClickHandler,LoaderManager.LoaderCallbacks<List<Movie>> {
...
@Override
protected void onCreate(Bundle savedInstanceState) {
...
getSupportLoaderManager().initLoader(LOADER_ID,getUrlBundle(),this);
}
...
@Override
public Loader<List<Movie>> onCreateLoader(int i, final Bundle bundle) {
return new AsyncTaskLoader<List<Movie>>(this) {
@Override
protected void onStartLoading() {
if(bundle==null)
return;
progressBar.setVisibility(View.VISIBLE);
errorMessage.setVisibility(View.INVISIBLE);
forceLoad();
}
@Override
public List<Movie> loadInBackground() {
/* Extract the url from the args using our constant */
String UrlString = bundle.getString(URL_EXTRA);
/* If the user didn't enter anything, there's nothing to search for */
if (UrlString == null || TextUtils.isEmpty(UrlString)) {
return null;
}
return QueryUtils.fetchMovieData(UrlString);
}
@Override
public void deliverResult(List<Movie> data) {
super.deliverResult(data);
}
};
}
@Override
public void onLoadFinished(Loader<List<Movie>> loader, List<Movie> movies) {
if (movies != null && !movies.isEmpty()) {
movieAdapter.MovieAdapterUpdate(movies);
progressBar.setVisibility(View.INVISIBLE);
} else {
progressBar.setVisibility(View.INVISIBLE);
errorMessage.setText("No data returned");
errorMessage.setVisibility(View.VISIBLE);
}
}
@Override
public void onLoaderReset(Loader<List<Movie>> loader) {
}
}
試し 'getSupportLoaderManager()initLoader(LOADER_ID、getUrlBundle()、MainActivity.this);。 ' – SripadRaj
それは輸入のためだと思われる – ams92