Get only one record from android database
I only need to get 1 record from android database. Submit watch to google, but can't write query as needed. I know it's a shame. Someone please help me. My request is below ...
Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null,null, null, null);
PS Sorry for the bad english.
+3
source to share
2 answers
Maybe you can try something like this:
public Strin getContactByName(String name)
{
String conact;
//Query
String query = "select * from CONTACTS where NAME = ?";
Cursor cursor = db.rawQuery(query, new String[] {name});
if(cursor.getCount()<1) // Name Not Exist
{
cursor.close();
contact = "Not Found";
return contact;
}
cursor.moveToFirst();
contact = cursor.getString(cursor.getColumnIndex("NAME"));
cursor.close();
return contact;
}
It will only return the first contact that matches that name.
+1
source to share