摘要: Activty部分: TestContacts.java:package waga.android.study.TestContacts; import android.app.Activity; import android.content.ContentResolver; import android.content.Intent; import android.data ...
Activty部分:
TestContacts.java:
1. package waga.android.study.TestContacts;
2. import android.app.Activity;
3. import android.content.ContentResolver;
4. import android.content.Intent;
5. import android.database.Cursor;
6. import android.os.Bundle;
7. import android.provider.ContactsContract;
8. import android.provider.ContactsContract.RawContacts;
9. import android.view.Menu;
10. import android.view.MenuInflater;
11. import android.view.MenuItem;
12. import android.widget.TextView;
13. public class TestContacts extends Activity
14. {
15. TextView myTextView;
16. String str;
17. @Override
18. public void onCreate(Bundle savedInstanceState)
19. {
20. super.onCreate(savedInstanceState);
21. setContentView(R.layout.main);
22. setTitle(R.string.ReadContact);
23. }
24.
25. // 创建选项菜单
26. @Override
27. public boolean onCreateOptionsMenu(Menu menu)
28. {
29. super.onCreateOptionsMenu(menu);
30. MenuInflater inflater = getMenuInflater();
31. inflater.inflate(R.layout.menu, menu);
32.
33. return true;
34. }
35. // 响应选项菜单
36. @Override
37. public boolean onOptionsItemSelected(MenuItem item)
38. {
39. switch (item.getItemId())
40. {
41. // 新建联系人
42. case R.id.menu_add:
43. {
44. // new一 个Intent对 象 , 并指定class
45. Intent intent = new Intent();
46. intent.setClass(this, NewContactActivity.class);
47. startActivity(intent);
48. return true;
49. }
50.
51. // 删除联系人
52. case R.id.menu_delete:
53. {
54. // new一 个Intent对 象 , 并指定class
55. Intent intent = new Intent();