gpt4 book ai didi

android - LoaderManager 未初始化... getLoaderManager().initLoader 的问题

转载 作者:行者123 更新时间:2023-11-29 14:23:16 25 4
gpt4 key购买 nike

我知道有很多这样的常见问题,但我似乎找不到解决方案。当我尝试使用 getLoaderManager().initLoader(LOADER_ID, null, this); 初始化加载程序时,错误 The method initLoader(int, Bundle, LoaderManager.LoaderCallbacks) in the type LoaderManager is not applicable for参数 (int, null, Gridview) 出现了。

这让我相信程序没有识别出 Gridview 实现了加载器管理器。我不确定这是为什么以及从这里去哪里。我尝试使用不同的进口产品,但这没有用。我还确保我有正确的下载来支持装载机。我正在使用的代码如下。

package com.example.camerapreview;

import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;

//Omissis imports


public class Gridview extends Activity implements LoaderManager.LoaderCallbacks<Cursor>{
private static final String TAG = "Checking Database";
private static final String TAG1 = "Checking Thumbnail";

Cursor cursor;
int columnindexid;
int columnindexdata;
int videoidindex;
int videopathindex;
GridviewData entry;
GridView gridview;
VideoAdapter videoadapter;
Cursor curs;

ImageLoaderConfiguration config;

String[] mediaColumns = {
MediaStore.Video.Media._ID,
MediaStore.Video.Media.DATA,
MediaStore.Video.Media.TITLE,
MediaStore.Video.Media.MIME_TYPE
};

private static final int LOADER_ID = 1;
int flags = 0;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.preview);
gridview = (GridView) this.findViewById(R.id.gridview);


cursor = getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, mediaColumns, null, null, null);
columnindexid = cursor.getColumnIndexOrThrow(MediaStore.Video.Media._ID);
columnindexdata = cursor.getColumnIndexOrThrow(MediaStore.Video.Media.DATA);

entry = new GridviewData(this);
entry.open();

getLoaderManager().initLoader(LOADER_ID, null, this);
DataEntry putitin = new DataEntry(entry, this);
putitin.execute();

//the cursor used in the cursor adapater
curs = entry.adapterCursor();
videoidindex = entry.Indexfinder(curs);
videopathindex = entry.Indexfinder2(curs);

config = new ImageLoaderConfiguration.Builder(this)
.imageDownloader(new BaseImageDownloader(this))
.build();

ImageLoader.getInstance().init(config);
Log.i(TAG, "Before set adapater");
gridview.setAdapter(new VideoAdapter(this, curs, flags));
}
}

编辑:

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
String[] projection = { GridviewData.VIDEOID, GridviewData.VIDEOFILEPATH };
return new CursorLoader(Gridview.this, MyContentProvider.CONTENT_URI, projection, null, null, null);
}

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor c) {
cursoradapter.swapCursor(c);
}

@Override
public void onLoaderReset(Loader<Cursor> loader) {
cursoradapter.swapCursor(null);
}

最佳答案

错误是由您的导入引起的:

import android.support.v4.app.LoaderManager;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;

它们适用于 FragmentActivity 但您使用的是普通 Activity 所以它们应该是:

import android.app.LoaderManager;
import android.app.LoaderManager.LoaderCallbacks;
import android.content.CursorLoader;
import android.content.Loader;
import android.widget.CursorAdapter;

请注意,在这种情况下,您的 android:minSdkVersion 应该是 11。如果您需要与较低版本兼容,只需保持导入原样并使用 FragmentActivity

关于android - LoaderManager 未初始化... getLoaderManager().initLoader 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17192316/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com