首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android入门户十五篇之ActivityGroup实现Tab分页标签

2012-08-25 
Android入门第十五篇之ActivityGroup实现Tab分页标签很多客户端软件和浏览器软件都喜欢用Tab分页标签来管

Android入门第十五篇之ActivityGroup实现Tab分页标签

很多客户端软件和浏览器软件都喜欢用Tab分页标签来管理内容,除了可以用TabHost控件,还可以用ImageButton + ActivityGroup实现Tab分页标签。使用ImageButton + ActivityGroup实现Tab分页标签,主要是把一个Sub Activity(子Activity)的Window作为View添加到ActivityGroup所指定的容器中,本文使用LinearLayout作为容器装载Sub Activity。

testActivityGroup.java源码如下:

view plaincopy to clipboardprint?
  1. package?com.testActivityGroup;????
  2. import?android.app.Activity;??import?android.os.Bundle;??
  3. import?android.util.Log;??import?android.widget.ArrayAdapter;??
  4. import?android.widget.ListView;????
  5. public?class?subActivity?extends?Activity?{??????String?name;??
  6. ??????public?void?onCreate(Bundle?savedInstanceState)?{??
  7. ????????super.onCreate(savedInstanceState);??????????setContentView(R.layout.listview);??
  8. ??????????//?读取列表内容??
  9. ????????name?=?this.getIntent().getStringExtra("Name");??????????String[]?str?=?this.getIntent().getStringArrayExtra("Strings");??
  10. ????????int?choiceMode?=?this.getIntent().getIntExtra("ChoiceMode",??????????????????ListView.CHOICE_MODE_NONE);??
  11. ??????????ListView?listView?=?(ListView)?findViewById(R.id.MyListView);??
  12. ??????????//?设置列表的式样??
  13. ????????int?itemID?=?android.R.layout.simple_list_item_1;??????????if?(choiceMode?==?ListView.CHOICE_MODE_MULTIPLE)//?主Activity要求多选??
  14. ????????????itemID?=?android.R.layout.simple_list_item_multiple_choice;??????????else?if?(choiceMode?==?ListView.CHOICE_MODE_SINGLE)//?主Activity要求单选??
  15. ????????????itemID?=?android.R.layout.simple_list_item_single_choice;????
  16. ????????ArrayAdapter<String>?arrayAdapter?=?new?ArrayAdapter<String>(this,??????????????????itemID,?str);??
  17. ????????listView.setAdapter(arrayAdapter);????
  18. ????????listView.setChoiceMode(choiceMode);????
  19. ????????Log.e(name,?"onCreate");//?显示当前状态,onCreate与onDestroy对应??????}??
  20. ????@Override??????public?void?onDestroy()?{??
  21. ????????super.onDestroy();??????????Log.e(name,?"onDestroy");//?显示当前状态,onCreate与onDestroy对应??
  22. ????}????
  23. ????@Override??????public?void?onStart()?{??
  24. ????????super.onStart();??????????Log.e(name,?"onStart");//?显示当前状态,onStart与onStop对应??
  25. ????}????
  26. ????@Override??????public?void?onStop()?{??
  27. ????????super.onStop();??????????Log.e(name,?"onStop");//?显示当前状态,onStart与onStop对应??
  28. ????}????
  29. ????@Override??????public?void?onRestart()?{??
  30. ????????super.onRestart();??????????Log.e(name,?"onRestart");??
  31. ????}????
  32. ????@Override??????public?void?onResume()?{??
  33. ????????super.onResume();??????????Log.e(name,?"onResume");//?显示当前状态,onPause与onResume对应??
  34. ????}????
  35. ????@Override??????public?void?onPause()?{??
  36. ????????super.onResume();??????????Log.e(name,?"onPause");//?显示当前状态,onPause与onResume对应??
  37. ????}??}?

热点排行