Android Getcontentresolver().query Error
I'm rather new to both Java programming and to Android development, so my learning curve is rather steep at the moment. I seem to be stuck on something that I can't find decent exa
Solution 1:
Well, it appears that I have arrived at the solution for my problem on my own. (after having pulled the hair out of my head and becoming fashionably bald)
It seems that the use of the Phone.TYPE was most definitely the problem, indeed. Phone.TYPE is a constant and not a data column.
It turns out that the code that worked perfectly was this;
privatevoidfillData() {
// This goes and gets all the contacts that have mobile numbers
final ArrayList<String> contacts = newArrayList<String>();
// Let's set our local variable to a reference to our listview control// in the view.
lvContacts = (ListView) findViewById(R.id.lvContacts);
String[] proj_2 = newString[] {Data._ID, Phone.DISPLAY_NAME, CommonDataKinds.Phone.TYPE};
phnCursor = managedQuery(Phone.CONTENT_URI, proj_2, null, null, null);
while(phnCursor.moveToNext()) {
if ( phnCursor.getInt(2) == Phone.TYPE_MOBILE ) {
String name = phnCursor.getString(1);
contacts.add(name);
}
}
// Make the array adapter for the listview.
final ArrayAdapter<String> aa;
aa = newArrayAdapter<String>(this,
android.R.layout.simple_list_item_multiple_choice,
contacts);
// Let's sort our resulting data alphabetically.
aa.sort(newComparator<String>() {
public int compare(String object1, String object2) {
return object1.compareTo(object2);
};
});
// Give the list of contacts over to the list view now.
lvContacts.setAdapter(aa);
}
I appreciate the help, but unfortunately must say that thorough bouts of madness and research eventually paid off. Hopefully this helps someone else out.
Post a Comment for "Android Getcontentresolver().query Error"