单个选项卡中的2个活动

时间:2011-10-20 04:57:18

标签: android tabs

我有4个标签。一个标签1(回复)我想开始另一个活动说点击继续按钮,应该转到另一个页面(Respond1),我有后退按钮。一切都应该在Tab 1本身。我有问题,如果我去4到5次我得到堆栈溢流错误。

Respond.Java

package com.muo.Livegroups;

import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.util.Log;

public class Respond extends ActivityGroup 
{
    protected static LocalActivityManager mLocalActivityManager;
    public static final String LOG_TAG = "muo";
    @Override   
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.respond);

        //Continue button on Respond page
        Button next1 = (Button) findViewById(R.id.Continue);
        next1.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View view) 
            {
                Intent myIntent = new Intent(view.getContext(), Respond1.class);
                startActivityForResult(myIntent, 0);
            //  StringBuffer urlString = new StringBuffer();
            //  myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            //  replaceContentView("Respond1",myIntent);

                int mInt=0;
                Log.v(LOG_TAG, "mInt Value: " + mInt);
            }
        });
    }

    public void replaceContentView(String id, Intent newIntent) 
    {
        View view = getLocalActivityManager()
                        .startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY ))
                        .getDecorView(); 
        this.setContentView(view);
    }
}

Respond1.Java

package com.muo.Livegroups;

import android.app.ActivityGroup;
import android.app.LocalActivityManager;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class Respond1 extends ActivityGroup 
{
    protected static LocalActivityManager mLocalActivityManager;
    public static final String LOG_TAG = "muo1";
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.respond1);

        Button next = (Button) findViewById(R.id.Button03);
        next.setOnClickListener(new View.OnClickListener() 
        {
            public void onClick(View view) 
            {
                Intent intent = new Intent();
                setResult(RESULT_OK, intent);
                finish();
            //  Intent myIntent = new Intent(view.getContext(), Respond.class);
            //  StringBuffer urlString = new StringBuffer();
            //  myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            //  replaceContentView("Respond",intent);

                int mInt1=0;
                Log.v(LOG_TAG, "mInt Value: " + mInt1);
            }
        });
    }

    public void replaceContentView(String id, Intent newIntent) 
    {
        View view = getLocalActivityManager()
                        .startActivity(id,newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP ))
                        .getDecorView(); 
        this.setContentView(view);
    }
}

2 个答案:

答案 0 :(得分:1)

您应该考虑制作两个活动fragments并将它们放在标签中的一个活动中。如果您使用的api级别低于3.0,请查看android compatibility package

答案 1 :(得分:0)

  

主要活动应该是ActivityGroup,并将此代码放在开始新活动的地方

  Intent intent = new Intent(v.getContext(), Activity1.class);
Activity1 parentActivity = (Activity1)getParent();  
parentActivity.replaceContentView("activity1", intent, 
             Intent.FLAG_ACTIVITY_REORDER_TO_FRONT );