Cap*_*son 4 java android asynchronous this loader
好的,我投降了.我想不明白.
我正在关注Android Basics的Udacity课程,需要弄清楚如何使用Loader加载数据.但是,当我使用以下行时,"this"以红色突出显示并显示以下错误:
Wrong 3rd argument type. Found 'com.example.carl.latestnews.MainActivity', required: 'android.app.LoaderManager.LoaderCallbacks<java.lang.Object>
Run Code Online (Sandbox Code Playgroud)
我用谷歌搜索,堆积并尝试了我发现的建议.我已经尝试创建一个实现回调的内部类.我碰到了一堵砖墙,我坐在这里挠挠脑袋想弄清楚我错过了什么!
谁能告诉我这里我做错了什么?
提前致谢!
package com.example.carl.latestnews;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.AsyncTaskLoader;
import android.support.v4.content.Loader;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<ArrayList<ArticleObject>> {
// ArticleObject is a custom object which contains a headline, date, category etc of a news article
// URL for Guardian API including API Key
final static String GUARDIAN_API_URL = "https://content.guardianapis.com/search?";
// API Key
final static String GUARDIAN_API_KEY = "test";
// ID for LoaderManager
final static int LOADER_MANAGER_ID = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get or initialize loader manager
getLoaderManager().initLoader(LOADER_MANAGER_ID, null, this);
}
@Override
public Loader<ArrayList<ArticleObject>> onCreateLoader(int id, Bundle args) {
return new dataLoader(); // dataLoader() removed for easy reading
}
@Override
public void onLoadFinished(Loader<ArrayList<ArticleObject>> loader, ArrayList<ArticleObject> data) {
/ UI Update Code
}
@Override
public void onLoaderReset(Loader<ArrayList<ArticleObject>> loader) {
// Reset Code
}
}
Run Code Online (Sandbox Code Playgroud)
小智 12
变化: getLoaderManager()到getSupportLoaderManager();
像这样:
getLoaderManager().initLoader(ID_FAVORITE_METAINFO_LOADER, args, this);
To
getSupportLoaderManager().initLoader(ID_FAVORITE_METAINFO_LOADER, args, this);