[英]CursorLoader cannot be converted to Loader<Cursor>
I am trying to display user data in ProfileFragment
Fragment.我正在尝试在
ProfileFragment
片段中显示用户数据。 So that I implemented LoaderManager.LoaderCallbacks<Cursor>
but following error occurs:所以我实现了
LoaderManager.LoaderCallbacks<Cursor>
但发生以下错误:
CursorLoader cannot be converted to Loader<Cursor>
How can I solve it?我该如何解决?
I searched on Google but couldn't find the correct solution for my problem.我在 Google 上搜索,但找不到适合我的问题的正确解决方案。 Any solution for this?
有什么解决办法吗?
Thank You in Advance.先感谢您。
ProfileFragment.java ProfileFragment.java
package com.example.takeattendence;
import android.content.Context;
import android.content.CursorLoader;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.BaseColumns;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ListView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.loader.app.LoaderManager;
import androidx.loader.content.Loader;
import com.example.takeattendence.database.LoginContract;
public class ProfileFragment extends Fragment implements LoaderManager.LoaderCallbacks<Cursor>
{
private static final int PET_LOADER = 0;
LoginCursorAdapter mLoginCursorAdapter;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
{
View view = inflater.inflate(R.layout.fragment_profile,container,false);
ListView listView = view.findViewById(R.id.profile_list);
mLoginCursorAdapter = new LoginCursorAdapter(getActivity(),null);
listView.setAdapter(mLoginCursorAdapter);
getLoaderManager().initLoader(PET_LOADER,null,this);
return view;
}
@NonNull
@Override
public Loader<Cursor> onCreateLoader(int id, @Nullable Bundle args) {
String[] projection = {
BaseColumns._ID,
LoginContract.LoginEntry.COLUMN_FIRST_NAME,
LoginContract.LoginEntry.COLUMN_PHONE_NUMBER,
LoginContract.LoginEntry.COLUMN_EMAIL_ID,
LoginContract.LoginEntry.COLUMN_PASSWORD,
LoginContract.LoginEntry.COLUMN_POST,
LoginContract.LoginEntry.COLUMN_GENDER
};
//error occurs at this line
return new CursorLoader(getContext(),
LoginContract.LoginEntry.CONTENT_URI,
projection,
null,
null,
null);
return null;
}
@Override
public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor data) {
mLoginCursorAdapter.swapCursor(data);
}
@Override
public void onLoaderReset(@NonNull Loader<Cursor> loader) {
mLoginCursorAdapter.swapCursor(null);
}
}
You import android.content.CursorLoader
, but you have to import androidx.loader.content.CursorLoader
instead, because you're also using the Loader from AndroidX ( androidx.loader.content.Loader
).您导入
android.content.CursorLoader
,但您必须导入androidx.loader.content.CursorLoader
,因为您还使用 AndroidX 的加载器( androidx.loader.content.Loader
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.