本文介绍了对于类型SimpleCursorAdapter,未定义swapCursor(Cursor)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
创建CursorLoader时,出现 swapCursor(Cursor)is undefined错误。我有
导入了android.support.v4(app.LoaderManager,app.LoaderManager.Loader,Content.CursorLoader,content.Loader)。不知道该如何解决该问题。
I am receiving a "swapCursor(Cursor) is undefined" error when creating a CursorLoader. I haveimported the android.support.v4 (app.LoaderManager, app.LoaderManager.Loader, Content.CursorLoader, content.Loader). Not sure what I can do to correct this issue. please advise.
loader:
import android.support.v4.app.Fragment;
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.app.ListFragment;
import android.support.v4.widget.CursorAdapter;
public class LoginList extends FragmentActivity implements OnClickListener, AdapterView.OnItemClickListener, LoaderManager.LoaderCallbacks<Cursor> {
private ListView loginList;
private Button webLogin;
private SimpleCursorAdapter adapter;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_listview);
loginList = (ListView)findViewById(R.id.loginlist);
loginList.setOnItemClickListener(this);
webLogin = (Button)findViewById(R.id.button3);
webLogin.setOnClickListener(this);
//Specify fileds to display in the list
String[] from = new String[] { ListProvider.COLUMN_NAME_SITE };
//Bind fields to listview
int[] to = new int[] {R.id.loginlist};
// Create CursorAdapter and set it to display
adapter = new SimpleCursorAdapter(this, R.layout.login_listview, null, from, to);
loginList.setAdapter(adapter);
getSupportLoaderManager().initLoader(0, null, this);
}
/*@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setEmptyText(getResources().getString(string.app_name));
rwgisterForContextMenu(getListView());
setHasOptionsMenu(true);
} */
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// TODO Auto-generated method stub
Toast.makeText(getApplicationContext(), "Selected ID :" + arg2, Toast.LENGTH_SHORT).show();
Intent updateDeleteLoginInfo = new Intent (this, UpdateDeleteLoginList.class);
Cursor clickedObject = (Cursor)loginList.getItemAtPosition(arg2);
Bundle loginBundle = new Bundle();
loginBundle.putString("clickedWebSite",((LoginDetails) clickedObject).getsName());
loginBundle.putString("clickedWebAddress",((LoginDetails) clickedObject).getwUrl());
loginBundle.putString("clickedUserName",((LoginDetails) clickedObject).getuName());
loginBundle.putString("clickedPassWord",((LoginDetails) clickedObject).getpWord());
loginBundle.putString("clickedNotes",((LoginDetails) clickedObject).getlNotes());
updateDeleteLoginInfo.putExtras(loginBundle);
startActivityForResult(updateDeleteLoginInfo, 0);
}
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent webLoginIntent = new Intent (this, LoginPlusActivity.class);
startActivity(webLoginIntent);
}
@Override
public Loader<Cursor> onCreateLoader(int ignored, final Bundle args) {
return new CursorLoader(this, ListProvider.CONTENT_URI, null, null, null, null);
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
adapter.swapCursor(cursor); /* swapCursor error: The method swapCursor(Cursor) is undefined for the type SimpleCursorAdapter */
}
@Override
public void onLoaderReset (Loader<Cursor> loader) {
adapter.swapCursor(null); /* swapCursor error: The method swapCursor(Cursor) is undefined for the type SimpleCursorAdapter */
}
}
推荐答案
问题通过导入v4.widget.simplecursoradapter来解决。
issue was resolved by importing v4.widget.simplecursoradapter.
import android.support.v4.widget.SimpleCursorAdapter;
这篇关于对于类型SimpleCursorAdapter,未定义swapCursor(Cursor)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!