我使用以下代码在列表视图中显示电话联系人:
LayoutInflater inflater = getLayoutInflater();
View dialoglayout = inflater.inflate(R.layout.contact_list, null);
AlertDialog.Builder builder = new AlertDialog.Builder(Etelaat.this);
builder.setView(dialoglayout);
listContacts = (ListView) dialoglayout.findViewById(R.id.conactlist);
Uri queryUri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME};
String selection = ContactsContract.Contacts.DISPLAY_NAME + " IS NOT NULL";
CursorLoader cursorLoader = new CursorLoader(Etelaat.this, queryUri, projection, selection, null, null);
Cursor cursor = cursorLoader.loadInBackground();
String[] from = {ContactsContract.Contacts.DISPLAY_NAME};
int[] to = {android.R.id.text1};
ListAdapter adapter = new SimpleCursorAdapter(Etelaat.this,android.R.layout.simple_list_item_1, cursor,from, to, CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
listContacts.setAdapter(adapter);
listContacts.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// ??????????????????
}
});
我需要点击列表视图项目获取联系电话号码并将其保存为String或int,那我该怎么做?