我正在制作一个音乐播放器,我只是想使用 ListFragment 显示艺术家姓名。这是代码:
import android.app.ListFragment;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.MediaStore;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class AlbumsFragment extends ListFragment implements
LoaderManager.LoaderCallbacks < Cursor > {
AlbumsAdapter mAdapter;
@
Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View myFragmentView = inflater.inflate(R.layout.tabs_list, container, false);
return myFragmentView;
}
@
Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mAdapter = new AlbumsAdapter(getActivity(), null);
setListAdapter(mAdapter);
getLoaderManager().initLoader(0, null, this);
}
static final String[] ALBUM_SUMMARY_PROJECTION = {
MediaStore.Audio.Albums._ID, MediaStore.Audio.Albums.ALBUM
};
public Loader < Cursor > onCreateLoader(int id, Bundle args) {
String select = null;
return new CursorLoader(getActivity(), MediaStore.Audio.Albums.EXTERNAL_CONTENT_URI, ALBUM_SUMMARY_PROJECTION, select, null, null);
}
public void onLoadFinished(Loader < Cursor > loader, Cursor data) {
mAdapter.swapCursor(data);
}
public void onLoaderReset(Loader < Cursor > loader) {
mAdapter.swapCursor(null);
}
}
我收到一条错误消息:LoaderManager 类型中的方法 initLoader(int, Bundle, LoaderManager.LoaderCallbacks) 不适用于参数 (int, null, AlbumsFragment)