간단히 ListView 형태로 전화번호부 가져오는 코드를 짜봤습니다.
저는 목록에 있는 사람들에 전화번호부를 다가져오네요.. 한번 비교해보시겠어요?
String [] projection = new String[] {
Phone._ID,
Phone.DISPLAY_NAME,
Phone.NUMBER
};
Cursor cursor = getContentResolver().query(
// uri,
Phone.CONTENT_URI,
projection,
null,
null,
Phone.DISPLAY_NAME);
ListView list = (ListView)findViewById(R.id.list);
MyAdapter adapter = new MyAdapter(this, cursor, true);
list.setAdapter(adapter);
}
private class MyAdapter extends CursorAdapter {
public MyAdapter(Context context, Cursor c, boolean autoRequery) {
super(context, c, autoRequery);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
TextView name = (TextView)view.findViewById(R.id.name);
TextView phone = (TextView)view.findViewById(R.id.phone);
name.setText(cursor.getString(cursor.getColumnIndex(Phone.DISPLAY_NAME)));
phone.setText(cursor.getString(cursor.getColumnIndex(Phone.NUMBER)));
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
LayoutInflater vi = LayoutInflater.from(context);
return vi.inflate(R.layout.items, null);
}
}