Android documentation said: This method was deprecated in API level 11.
This is code:
class GridViewActivity_ extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.gridview);
GridView gv = (GridView)findViewById(R.id.gridview);
Cursor c = managedQuery(Contacts.CONTENT_URI,
null, null, null, Contacts.DISPLAY_NAME);
String[] cols = new String[]{Contacts.DISPLAY_NAME};
int[] views = new int[] {android.R.id.text1};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
android.R.layout.simple_list_item_1,
c, cols, views);
gv.setAdapter(adapter);
}
}
How replace this code , not deprecated code?
For activity, not fragment...
You can see this link : Deprecated ManagedQuery() issue
Cursor cursor = getContentResolver().query(contentUri, null, null, null, Contacts.DISPLAY_NAME);
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);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With