[英]How to show Tabs in the in th SubActivity?
I make an application in which i had made 5 Tabs on the First Tab there is a ListView When i Click on any ListItem i had call another activity with intent .Now there us a problem As & when i click on Listitem The Tabs will Dissapears How can i show Tabs on my SubActivity . 我制作了一个应用程序,其中我在第一个选项卡上制作了5个选项卡,当我单击任何ListItem时我有一个意图调用了另一个活动。现在有一个问题,当我单击Listitem时,选项卡将消失我可以在SubActivity上显示选项卡吗?
Any help willl be Appretiated. 任何帮助将不胜感激。
That is the normal behavior in Android, not very nice. 这是Android中的正常行为,不是很好。
I usually create the first Activity in a Tab extending from this class 我通常在从此类扩展的Tab中创建第一个Activity
public class TabActivityGroup extends ActivityGroup {
protected LocalActivityManager manager;
protected ArrayList<String> mIdList;
public TabActivityGroup() {
this(false);
}
public TabActivityGroup(boolean single) {
super(single);
}
public void onCreate(Bundle ins) {
super.onCreate(ins);
manager = getLocalActivityManager();
mIdList = new ArrayList<String>();
}
public void startChildActivity(String Id, Intent intent) {
Log.d(this.getClass().getName(), "startChildActivity " + Id + " / " + mIdList.size());
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Window window = manager.startActivity(Id, intent);
if (window != null) {
mIdList.add(Id);
setContentView(window.getDecorView());
}
}
@Override
public void finishFromChild(Activity child) {
Log.d(this.getClass().getName(), "finishFromChild("+child.getClass().getName()+") mIdList.size " + mIdList.size());
int index = mIdList.size() - 1;
if (index < 1) {
finish();
}else{
Log.e(getClass().getName(), "destroy " + mIdList.get(index));
manager.destroyActivity(mIdList.get(index), true);
mIdList.remove(index);
index--;
String lastId = mIdList.get(index);
Activity previous = manager.getActivity(lastId);
setContentView(previous.getWindow().getDecorView());
}
}
/**
* Overrides the default implementation for KeyEvent.KEYCODE_BACK so that
* all systems call onBackPressed().
*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
goBack();
return true;
}
return super.onKeyUp(keyCode, event);
}
public void goBack() {
Log.d(this.getClass().getName(), "goBACK() : " + mIdList.size());
int length = mIdList.size();
if (length > 1) {
Activity current = manager.getActivity(mIdList.get(length - 1));
current.finish();
}else{
((MyApplication)getApplication()).systemExit(this);
//This just calls to System.exit
}
}
}
You can then create a Tab like this 然后您可以创建一个这样的标签
public class TabOne extends TabActivityGroup {
@Override
public void onCreate(Bundle b) {
super.onCreate(b);
startChildActivity(OneActivity.class.getName(), new Intent(this, OneActivity.class));
}
Things to keep in mind: 注意事项:
The tab has nothing inside, just starts the real tab activity with 该标签页内部没有任何内容,只需使用
the startChildActivity
method. startChildActivity
方法。 This is to get a nice behavior when going back and reach the first activity and the app needs to close. 当返回并达到第一个活动并且应用程序需要关闭时,这是一种很好的行为。
Be very careful with the Context
on the subactivities as you have 您必须对子活动的
Context
非常小心
to use the TabActivityGroup
context. 使用
TabActivityGroup
上下文。 You can do this manually by 您可以通过以下方式手动执行此操作
calling getParent()
, or better defining a method that loops calling getParent()
until you find the root parent. 调用
getParent()
或更好地定义一个循环调用getParent()
的方法,直到找到根父级为止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.