好吧,我投降了。我想不明白。LoaderManager不接受'this'
我正在關注Android基礎知識的Udacity課程,需要弄清楚如何使用Loader加載數據。然而,當我使用下面的行中,「這個」被以紅色突出顯示,並顯示以下錯誤:
Wrong 3rd argument type. Found 'com.example.carl.latestnews.MainActivity', required: 'android.app.LoaderManager.LoaderCallbacks<java.lang.Object>
我GOOGLE了,堆疊並試圖建議,我已經找到。我試過創建一個實現回調的內部類。我碰到了一個磚牆,我坐在這裏撓撓頭,試圖找出我失蹤的東西!
任何人都可以告訴我我在做什麼錯嗎?
在此先感謝!
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
}
}
請編輯您的問題,並提供你的'dataLoader'類定義。 – CommonsWare