Android入门户十五篇之ActivityGroup实现Tab分页标签
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?
- package?com.testActivityGroup;????
- import?android.app.Activity;??import?android.os.Bundle;??
- import?android.util.Log;??import?android.widget.ArrayAdapter;??
- import?android.widget.ListView;????
- public?class?subActivity?extends?Activity?{??????String?name;??
- ??????public?void?onCreate(Bundle?savedInstanceState)?{??
- ????????super.onCreate(savedInstanceState);??????????setContentView(R.layout.listview);??
- ??????????//?读取列表内容??
- ????????name?=?this.getIntent().getStringExtra("Name");??????????String[]?str?=?this.getIntent().getStringArrayExtra("Strings");??
- ????????int?choiceMode?=?this.getIntent().getIntExtra("ChoiceMode",??????????????????ListView.CHOICE_MODE_NONE);??
- ??????????ListView?listView?=?(ListView)?findViewById(R.id.MyListView);??
- ??????????//?设置列表的式样??
- ????????int?itemID?=?android.R.layout.simple_list_item_1;??????????if?(choiceMode?==?ListView.CHOICE_MODE_MULTIPLE)//?主Activity要求多选??
- ????????????itemID?=?android.R.layout.simple_list_item_multiple_choice;??????????else?if?(choiceMode?==?ListView.CHOICE_MODE_SINGLE)//?主Activity要求单选??
- ????????????itemID?=?android.R.layout.simple_list_item_single_choice;????
- ????????ArrayAdapter<String>?arrayAdapter?=?new?ArrayAdapter<String>(this,??????????????????itemID,?str);??
- ????????listView.setAdapter(arrayAdapter);????
- ????????listView.setChoiceMode(choiceMode);????
- ????????Log.e(name,?"onCreate");//?显示当前状态,onCreate与onDestroy对应??????}??
- ????@Override??????public?void?onDestroy()?{??
- ????????super.onDestroy();??????????Log.e(name,?"onDestroy");//?显示当前状态,onCreate与onDestroy对应??
- ????}????
- ????@Override??????public?void?onStart()?{??
- ????????super.onStart();??????????Log.e(name,?"onStart");//?显示当前状态,onStart与onStop对应??
- ????}????
- ????@Override??????public?void?onStop()?{??
- ????????super.onStop();??????????Log.e(name,?"onStop");//?显示当前状态,onStart与onStop对应??
- ????}????
- ????@Override??????public?void?onRestart()?{??
- ????????super.onRestart();??????????Log.e(name,?"onRestart");??
- ????}????
- ????@Override??????public?void?onResume()?{??
- ????????super.onResume();??????????Log.e(name,?"onResume");//?显示当前状态,onPause与onResume对应??
- ????}????
- ????@Override??????public?void?onPause()?{??
- ????????super.onResume();??????????Log.e(name,?"onPause");//?显示当前状态,onPause与onResume对应??
- ????}??}?