问题描述
在我的应用程序,我想从使用意图的选项卡按钮打开活动。而不是开在同一个选项卡,但新的活动覆盖整个屏幕和选项卡不可见萦绕。我如何打开在同一个标签一个以上的活动。
In my application I am trying to open an activity from a button in tab using intent. But instead of opening in the same tab the new activity covers the entire screen and the tabs are no linger visible.. How can I open more than one activity in the same tab..
下面code是我的主类的:
The following code is of my main class:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
TabHost tabHost = getTabHost();
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("OPT").setContent(new Intent(this, TabGroup1Activity.class)));
tabHost.addTab(tabHost.newTabSpec("tab2").setIndicator("EDIT").setContent(new Intent(this, TabGroup2Activity.class)));
tabHost.setCurrentTab(1);
}
下面是TabGroupActivity的code:
The following is the code of TabGroupActivity:
public class TabGroupActivity extends ActivityGroup{
ArrayList<String> list;
Window window;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
if(list.equals(null))
{
list = new ArrayList<String>();
}
}
@Override
public void finishFromChild(Activity child)
{
LocalActivityManager manager = getLocalActivityManager();
int index = list.size() -1;
if(index < 1)
{
finish();
return;
}
manager.destroyActivity(list.get(index), true);
list.remove(index);
index--;
String lastId = list.get(index);
Intent in = manager.getActivity(lastId).getIntent();
window = manager.startActivity(lastId, in);
setContentView(window.getDecorView());
}
public void startChildActivity(String Id, Intent intent)
{
window = getLocalActivityManager().startActivity(Id, intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
if(window != null)
{
list.add(Id);
setContentView(window.getDecorView());
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK)
return true;
return super.onKeyDown(keyCode, event);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event)
{
if(keyCode == KeyEvent.KEYCODE_BACK)
{
onBackPressed();
return true;
}
return super.onKeyUp(keyCode, event);
}
@Override
public void onBackPressed()
{
int length = list.size();
if(length > 1)
{
Activity current = getLocalActivityManager().getActivity(list.get(length - 1));
current.finish();
}
}
}
在$ C $下TabGroup1Activity的TabGroup2Activity也有同样的code:
The code for TabGroup1Activity the TabGroup2Activity also having the same code:
public class TabGroup1Activity extends TabGroupActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
startChildActivity("TestClass", new Intent(this,TestClass.class));
}
}
code为TestClass的活动:
Code for the TestClass activity:
public class TestClass extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.newview);
}
}
请帮我在解决我的问题。
Please help me is solving my problem..
在此先感谢...
推荐答案
您可以使用它的 ..check的
You can do it using fragments..check http://mobile.tutsplus.com/tutorials/android/android-compatibility-working-with-fragments/
这篇关于单标签Android的多种活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!