Chaoz
Fortgeschrittenes Mitglied
- 13
Hi Leute,
ich hab aus dem Android SDK2.0 samples ne kleine app, die mir die contacts anzeigt.
Nur habe ich nun das problem, dass ich NUR contacts haben will, die mindestens eine eMail haben. =/
Irgend Jmd eine idee?
code:
ich hab aus dem Android SDK2.0 samples ne kleine app, die mir die contacts anzeigt.
Nur habe ich nun das problem, dass ich NUR contacts haben will, die mindestens eine eMail haben. =/
Irgend Jmd eine idee?
code:
Code:
package com.cortado;
import android.app.Activity;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.CompoundButton.OnCheckedChangeListener;
public class ContactManager extends Activity {
public static final String TAG = "ContactManager";
// private Button mAddAccountButton;
private ListView mContactList;
/**
* Called when the activity is first created. Responsible for initializing the UI.
*/
@Override
public void onCreate(Bundle savedInstanceState)
{
Log.v(TAG, "Activity State: onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.contact_manager);
// Obtain handles to UI objects
mContactList = (ListView) findViewById(R.id.contactList);
// Initialize class properties
// Register handler for UI elements
// Populate the contact list
populateContactList();
}
/**
* Populate the contact list based on account currently selected in the account spinner.
*/
private void populateContactList() {
// Build adapter with contact entries
Cursor cursor = getContacts();
String[] fields = new String[] { ContactsContract.Data.DISPLAY_NAME };
for(String s : fields)
{
System.out.println("#> " + s);
}
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contact_entry, cursor, fields, new int[] {R.id.contactEntryText});
mContactList.setAdapter(adapter);
}
/**
* Obtains the contact list for the currently selected account.
*
* @return A cursor for for accessing the contact list.
*/
private Cursor getContacts()
{
// Run query
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME };
// String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" + (mShowInvisible ? "0" : "1") + "'";
String[] selectionArgs = null;
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
return managedQuery(uri, projection, null, selectionArgs, sortOrder);
}
}