gpt4 book ai didi

java - 错误的第三个论点,但应该通过视频教程工作

转载 作者:太空狗 更新时间:2023-10-29 16:12:56 25 4
gpt4 key购买 nike

我正在关注 tutorial但是当我到达要制作的部分时:

getLoaderManager().initLoader(0, null, this);

this 造成了问题。它引用了 MainActivity 但它不会接受实现。

它的具体信息是:

Wrong 3rd argument type. Found: 'com.example.plainolnotes.MainActivity', required: 'android.app.LoaderManager.LoaderCallbacks

package com.example.plainolnotes;

import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
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.support.v4.widget.SimpleCursorAdapter;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;

public class MainActivity extends AppCompatActivity
implements LoaderManager.LoaderCallbacks<Cursor>
{
private CursorAdapter cursorAdapter;

// @TargetApi(Build.VERSION_CODES.JELLY_BEAN) //Not a good long term solution

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

insertNote("New_note");
/*
Cursor cursor = getContentResolver().query(NotesProvider.CONTENT_URI,
DBOpenHelper.ALL_COLUMNS, null, null, null, null);
*/
String[] from = {DBOpenHelper.NOTE_TEXT};
int[] to = {android.R.id.text1};

cursorAdapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1, null, from, to, 0);
ListView list = (ListView) findViewById(android.R.id.list);
list.setAdapter(cursorAdapter);

//getLoaderManager().initLoader(0, null, this);
getLoaderManager().initLoader(0, null, this);

/*
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
*/
}

private void insertNote(String noteText) {
ContentValues values = new ContentValues();
values.put(DBOpenHelper.NOTE_TEXT, noteText);
Uri noteUri = getContentResolver().insert(NotesProvider.CONTENT_URI,
values);
Log.d("MainActivity", "Inserted note " + noteUri.getLastPathSegment());
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

@Override
public Loader<Cursor> onCreateLoader(int id, Bundle args) {
//Loaded when data is needed for the contentProvider
return new CursorLoader(this, NotesProvider.CONTENT_URI,
null, null, null, null);
}

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
cursorAdapter.swapCursor(data);

}

@Override
public void onLoaderReset(Loader<Cursor> loader) {
//data needs to be wiped out
cursorAdapter.swapCursor(null);

}
}

最佳答案

问题出在导入语句上

import android.support.v4.app.LoaderManager;

而需要的是

android.app.LoaderManager.LoaderCallbacks

替换它来解决你的问题

关于java - 错误的第三个论点,但应该通过视频教程工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39341420/

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