我想在当前视图中启动一个新的活动意图!我怎么能这样做?
答案 0 :(得分:4)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:id="@+id/contentViewLayout"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:layout_marginBottom="56dip"/>
<HorizontalScrollView
android:scrollbarSize="2dip"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:background="@drawable/background" android:layout_height="56dip">
</HorizontalScrollView>
</RelativeLayout>
当我必须在其中开始新活动时,我使用以下代码......
public class MainActivityWithTabbar extends ActivityGroup implements OnClickListener{
public LocalActivityManager activityManager;
public LinearLayout contentViewLayout;
public LinearLayout.LayoutParams contentViewLayoutParams;
private Context context;
public Intent nextActivit;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
context = this;
activityManager = getLocalActivityManager();
setContentView(R.layout.mainActivityLayout);
contentViewLayout = (LinearLayout)findViewById(R.id.contentViewLayout);
contentViewLayoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
nextActivit = new Intent(this, NextActivity.class);
startGroupActivity("activity1", nextActivit);
}
public void startGroupActivity(String id, Intent intent)
{
contentViewLayout.removeAllViews();
View view = activityManager.startActivity(id, intent).getDecorView();
contentViewLayout.addView(view, contentViewLayoutParams);
}
}
所以在这种情况下它的工作......
答案 1 :(得分:0)
您的意思是视图中包含的活动吗?你不能这样做。视图包含可见元素,活动用于运行程序代码。
但是,如果您的意思是通过与视图交互来启动新活动,就像在用户单击按钮时一样,您需要实现onClick()方法,并从那里开始活动。
layout.xml
...
android:onClick="onButton"
MyActivity.java
...
public void onButton(View v) {
Intent i = new Intent(mCtx, OtherActivity.class);
startActivityForResult(i, OPTION);
}