What the appropriate replacer of deprecated “ managedQuery”?

元气小坏坏 提交于 2019-12-04 02:18:04
Harsh Parikh

You can see this link : Deprecated ManagedQuery() issue

Cursor cursor = getContentResolver().query(contentUri, null, null, null, Contacts.DISPLAY_NAME);
ilw

According to this great tutorial :

public class GridViewActivity extends FragmentActivity implements LoaderManager.LoaderCallbacks<Cursor>
{
    private SimpleCursorAdapter mAdapter;

    @Override
public Loader<Cursor> onCreateLoader(int p1, Bundle p2)
{
    return new CursorLoader(this, Contacts.CONTENT_URI, null, null, null, Contacts.DISPLAY_NAME);
}

@Override
public void onLoadFinished(Loader<Cursor> p1, Cursor cursor)
{
    mAdapter.swapCursor(cursor);
}

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


@Override
protected void onCreate(Bundle savedInstanceState)
{
    // TODO: Implement this method
    super.onCreate(savedInstanceState);
    setContentView(R.layout.gridview);      
    GridView gv = (GridView)findViewById(R.id.gridview);
    String[] cols = new String[]{Contacts.DISPLAY_NAME};
    int[] views = new int[]{android.R.id.text1};
    mAdapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, null, cols,views, 0);
    gv.setAdapter(mAdapter);
    getSupportLoaderManager().initLoader(0, null, this);
}

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!