Android:如何获得DISPLAY_NAME&使用cursorloader同时联系所有公司名称?

时间:2013-08-14 02:57:34

标签: android

我想获得DISPLAY_NAME&使用cursorloader同时刷新所有联系人的COMAPNY名称。我已经获得了它们的显示名称。 我的问题是我不知道如何与DISPLAY_NAME同时获取公司名称! 你能告诉我解决问题的方法吗?这是我的代码。

public class MainActivity extends ListActivity implements LoaderManager.LoaderCallbacks<Cursor>{
SimpleCursorAdapter mAdapter;       
LoaderManager loadermanager;    

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    loadermanager = getLoaderManager();     
    String[] fromColumns = {ContactsContract.Contacts._ID,
                            ContactsContract.Contacts.DISPLAY_NAME};        

    int[] toViews = {R.id.contactId,
                     R.id.contactName};

    mAdapter = new SimpleCursorAdapter(this,  
            R.layout.view_contact_entry, null,
            fromColumns, toViews, 0);


    setListAdapter(mAdapter);
    loadermanager.initLoader(1, null, this);
}

public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    String[] projection = new String[] {ContactsContract.CommonDataKinds.Phone._ID,
            ContactsContract.Contacts.DISPLAY_NAME};        
    String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '1'";

    String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";               
    return new CursorLoader(this, ContactsContract.Contacts.CONTENT_URI,
            projection, selection, null, sortOrder); 
}

public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if(mAdapter!=null && cursor!=null)
        mAdapter.swapCursor(cursor);
    else
        Log.v("MAIN","OnLoadFinished: mAdapter is null");
}

public void onLoaderReset(Loader<Cursor> loader) {
    mAdapter.swapCursor(null);
}
@Override 
public void onListItemClick(ListView l, View v, int position, long id) {
    try {
        Cursor cs = (Cursor)l.getItemAtPosition(position);
        Intent  objIndent = new Intent(getApplicationContext(),DetailContact.class);
        objIndent.putExtra("contactId", cs.getString(0)); 
        objIndent.putExtra("contactName", cs.getString(1)); 
        startActivity(objIndent);   
    } catch (Exception e) {
        Log.e("ERROR: ", e.getMessage());
    }
}

}

1 个答案:

答案 0 :(得分:-1)

我认为你需要查看ContactsContract.Data

的查询

有一个例子是从文档中的联系人加入和提取其他数据

以及此特殊常量ContactsContract.CommonDataKinds.Organization.COMPANY