我没有在互联网上找到任何解决方案,只有Android开发者的教程,遗憾的是只提供了一小部分代码。我最终得到了这样的东西:
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract.Data;
import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity implements LoaderManager.LoaderCallbacks<Cursor> {
// Defines the selection clause
private static final String SELECTION = Data.LOOKUP_KEY + " = ?"; // Defines the array to hold the search criteria
private String[] mSelectionArgs = { "" };
private String mLookupKey;
private static final String SORT_ORDER = Data.MIMETYPE;
final int DETAILS_QUERY_ID = 0;
private static final String PROJECTION[] = {
Data._ID, Data.MIMETYPE, Data.DATA1, Data.DATA2, Data.DATA3, Data.DATA4, Data.DATA5, Data.DATA6, Data.DATA7, Data.DATA8, Data.DATA9, Data.DATA10, Data.DATA11, Data.DATA12, Data.DATA13, Data.DATA14, Data.DATA15
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// getLoaderManager().initLoader(DETAILS_QUERY_ID, null, this);
}
@Override
public Loader<Cursor> onCreateLoader(int loaderId, Bundle args) {
switch (loaderId) {
case DETAILS_QUERY_ID:
// Assigns the selection parameter
mSelectionArgs[0] = mLookupKey; // Starts the query
CursorLoader mLoader = new CursorLoader(this, Data.CONTENT_URI, PROJECTION,
SELECTION, mSelectionArgs, SORT_ORDER);
}
return null; // TODO what should be here ?
}
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
}
@Override
public void onLoaderReset(Loader<Cursor> loader) {
// switch (loader.getId()) {
// case DETAILS_QUERY_ID:
// }
// break;
// }
}
}
我怎样才能让它发挥作用? https://developer.android.com/training/contacts-provider/retrieve-details.html确实缺少一些代码和解释