ApiDemos 类的 onCreate 方法的学习 – 热爱改变生活
我的GitHub GitHub |     登录
  • If you can't fly, then run; if you can't run, then walk; if you can't walk, then crawl
  • but whatever you do, you have to keep moving forward。
  • “你骗得了我有什么用,这是你自己的人生”
  • 曾有伤心之地,入梦如听 此歌

ApiDemos 类的 onCreate 方法的学习

Android sinvader 4608℃ 0评论

  1. public void onCreate(Bundle savedInstanceState) {
  2. super.onCreate(savedInstanceState);
  3. /**
  4. * 在 getIntent() 中是这么写的【Return the intent that started this activity】
  5. * 现在猜测应该是//FIXME 从别的 activity 回到这里的时候,可能会带回一个数据,也就是下面的 path
  6. */
  7. Intent intent = getIntent();
  8. String path = intent.getStringExtra("com.example.android.apis.Path");
  9. /**
  10. * 这里的 path 就是上面可能通过 intent 带过来的,但是也有可能没有(启动程序的时候)
  11. */
  12. if (path == null) {
  13. /**
  14. * 为空置为空字符串
  15. */
  16. path = "";
  17. }
  18. /**
  19. * ListActivity 的方法,源代码的注释是【Provide the cursor for the list
  20. * view.】英文不好就不献丑了。进入内部发现他最终还是调用了【mList.setAdapter(adapter)】,
  21. * 而这个 adapter 就是我们在下面传入进去的 adapter 本方法类似于我们平常写的:
  22. * mListView.setAdapter(mAdapter);
  23. *
  24. * 满头汗水阅读了 SimpleAdapter 的源码注释:
  25. *
  26. * @param 第 1 个参数 context
  27. * 是指与当前 adapter 有关的在运行中的 view 的上下文
  28. * @param 第 2 个参数 data
  29. * 是一个由好多 map 构成的一个 list
  30. * ,这个 list 中的每一个条目都相当于要在界面上面显示的一行,所有要显示的数据都存在所有的这些 maps 中,
  31. * 而且每一个 map 都必须要包含第四个参数中的 key 值
  32. * getData() 返回的数据中的一部分,其中就包括"title"【[{intent=Intent {
  33. * cmp=com.example.android.apis/.ApiDemos (has extras) },
  34. * title=Accessibility}, {intent=Intent {
  35. * cmp=com.example.android.apis/.ApiDemos (has extras) },
  36. * title=Animation}]】
  37. * @param 第 3 个参数 resource
  38. * 是一个资源文件 ,资源文件中的 id 必须包括参数 5 中所提供的
  39. * @param 第 4 个参数
  40. * 指 listview 中的每一项中获取那个列(字段)的值
  41. * @param 第 5 个参数
  42. * 指从第 4 个参数上面获得的数据要放在资源文件的那个 id 上面
  43. */
  44. setListAdapter(new SimpleAdapter(this, getData(path), android.R.layout.simple_list_item_1, new String[] { "title" }, new int[] { android.R.id.text1 }));
  45. /**
  46. * @param 第一部分
  47. * getListView() 是 ListActivity 中的一个方法,用来获得内置的 mListView。 在这个过程中,
  48. * 他对这个 listview 进行了确认, 如果在 ListActivity 中 mListView 是空的,他会调用
  49. * {@codesetContentView(com.android.internal.R.layout.list_content_simple);}
  50. * 而在 list_content_simple .xml 文件中包括
  51. * {@codeandroid:id="@android:id/list"}
  52. * 在 ListActivity 中是根据这个 id 来找到 mListView 的【mList =
  53. * {@code(ListView)findViewById(com.android.internal.R.id.list);】}
  54. *
  55. * @param 第二部分
  56. * mListview.setTextFilterEnabled(true) 这个方法的作用是用来过滤选项的.
  57. * 例如在软键盘上打出一个 a, 则会过滤掉除了 a 开头的所有选项.
  58. */
  59. getListView().setTextFilterEnabled(true);
  60. }
¥ 有帮助么?打赏一下~

转载请注明:热爱改变生活.cn » ApiDemos 类的 onCreate 方法的学习


本博客只要没有注明“转”,那么均为原创。 转载请注明链接:sumile.cn » ApiDemos 类的 onCreate 方法的学习

喜欢 (2)
发表我的评论
取消评论
表情

如需邮件形式接收回复,请注册登录

Hi,你需要填写昵称和邮箱~

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址