Custom Dialog 주소록 정보 출력

|
  1. public class CustomDialog extends Dialog implements android.view.View.OnClickListener{
  2. final String LOGTAG = "CUSTOMDIALOG";
  3. DBInfo_DataHelper dbHelper = new DBInfo_DataHelper();
  4. Context context;
  5. CheckBox finalProcess;
  6. String dialogType;
  7. public CustomDialog(Context context, String dialogType){ // 주소록 Dialog
  8. super(context);

  9. requestWindowFeature(Window.FEATURE_NO_TITLE);

  10. this.context = context;
  11. setContentView(R.layout.dialog_contactlist);
  12. Cursor contactRow = context.getContentResolver().query(Phone.CONTENT_URI
  13. , new String[] { "_id", "display_name", "data1" }
  14. , null
  15. , null
  16. , "display_name asc");

  17. String[] from = { "display_name", "data1" };
  18. int[] to = { R.id.dialog_contactlist_name, R.id.dialog_contactlist_phonenumber };
  19. DialogContactListCursorAdapter contactCursorAdapter = new DialogContactListCursorAdapter(context
  20. , R.layout.dialog_contactlist_listform
  21. , contactRow
  22. , from
  23. , to);
  24. ListView lv = (ListView)findViewById(R.id.dialog_contactlist);
  25. lv.setAdapter(contactCursorAdapter);
  26. }

  27. private class DialogContactListCursorAdapter extends SimpleCursorAdapter{
  28. public DialogContactListCursorAdapter(Context context, int layout, Cursor c,
  29. String[] from, int[] to) {
  30. super(context, layout, c, from, to);
  31. }

  32. @Override
  33. public void bindView(View view, Context context, Cursor cursor) {
  34. TextView name = (TextView)view.findViewById(R.id.dialog_contactlist_name);
  35. TextView phoneNumber = (TextView)view.findViewById(R.id.dialog_contactlist_phonenumber);
  36. name.setText(cursor.getString(1));
  37. phoneNumber.setText(cursor.getString(2));
  38. }
  39. }
  40. }



R.layout.dialog_contactlist
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.   xmlns:android="http://schemas.android.com/apk/res/android"
  4.   android:layout_width="fill_parent"
  5.   android:layout_height="fill_parent">
  6.   <ListView android:id="@+id/dialog_contactlist"
  7. android:layout_width="fill_parent"
  8. android:layout_height="wrap_content"/>
  9. </LinearLayout>



R.layout.dialog_contactlist_listform
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout
  3.   xmlns:android="http://schemas.android.com/apk/res/android"
  4.   android:orientation="vertical"
  5.   android:layout_width="fill_parent"
  6.   android:layout_height="fill_parent"
  7.   android:padding="5dp">
  8.   <TextView android:id="@+id/dialog_contactlist_name"
  9.    android:layout_width="fill_parent"
  10.    android:layout_height="wrap_content"
  11.    android:text="dialog_contactlist_name"/>
  12.   <TextView android:id="@+id/dialog_contactlist_phonenumber"
  13.    android:layout_width="fill_parent"
  14.    android:layout_height="wrap_content"
  15.    android:text="dialog_contactlist_phonenumber"/>
  16. </LinearLayout>

'Android' 카테고리의 다른 글

Activity 생애주기  (0) 2011.03.16
태스크란? (Task, Activity Stack)  (0) 2011.03.14
주소록 정보  (0) 2011.02.01
SMS 정보  (0) 2011.02.01
content://sms/ 필드명  (0) 2011.02.01
And