0

我有基于标签的应用程序。在一个选项卡中,我有一个扩展 ListActivity 的类。在保留标签栏的同时触发 onClick 时,我需要另一个活动。我想在保留标签栏的同时通过 onClick 转移到另一个标签。

此代码有效,但隐藏标签栏:

Intent intent = new Intent(getApplicationContext(),SectionContentList.class);   

// put values to intent which will get in the LoginSuccess    Activity
Log.d("",appState.MainCategories.get(position).get("feedUrl"));
intent.putExtra("FeedURL", appState.MainCategories.get(position).get("feedUrl"));

// Start LoginSuccess Activity
startActivity(intent);

如何在保留底部标签栏的同时转移到这个新意图?

4

3 回答 3

2

我给了你标签活动管理的例子//已经声明了标签活动使用的数量包 com.technosoft.Concina_Peru;

import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TabHost;
import android.widget.TextView;

import com.technosoft.FirstTab.FirstTab;
import com.technosoft.FourthTab.FourthTab;
import com.technosoft.SecondTab.SecondTab;
import com.technosoft.ThirdTab.ThirdTab;

public class ConcinaPeruTabbar extends TabActivity {

    public static Context tabContext;
    public static TabHost tabHost;
    Context con;
    public static String var = "";

    public static Concina_Database db;

    private void setupTabHost() {
        tabHost = (TabHost) findViewById(android.R.id.tabhost);
        tabHost.setup();
    }   

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.starttab);
        tabContext = this;
        con = this.getApplicationContext();
        db = new Concina_Database(con);

        setupTabHost();
        setupTab(new TextView(this), "Inicio");
        setupTab(new TextView(this), "Recetas");
        setupTab(new TextView(this), "Favoritos");
        setupTab(new TextView(this), "Mas");

    }



    private void setupTab(final View view, final String tag) {
        View tabview = createTabView(tabHost.getContext(), tag);
        if(tag.equals("Inicio")){

            tabHost.addTab((tabHost.newTabSpec("Inicio")).setIndicator(
                    tabview).setContent(new Intent(this, FirstTab.class)));
        }
        if(tag.equals("Recetas")){

        tabHost.addTab((tabHost.newTabSpec("Recetas")).setIndicator(
                tabview).setContent(new Intent(this, SecondTab.class)));

        }
        if(tag.equals("Favoritos")){

            tabHost.addTab((tabHost.newTabSpec("Favoritos")).setIndicator(
                tabview).setContent(new Intent(this, ThirdTab.class)));

        }
        if(tag.equals("Mas")){

            tabHost.addTab((tabHost.newTabSpec("Mas")).setIndicator(
                tabview).setContent(new Intent(this, FourthTab.class)));

        }
    }

    private static View createTabView(final Context context, final String text) {
        View view = LayoutInflater.from(context)
                .inflate(R.layout.tabs_bg, null);
        TextView tv = (TextView) view.findViewById(R.id.tabsText);

        ImageView iv = (ImageView) view.findViewById(R.id.imageView1);
        if (text.equals("Inicio")) {
            iv.setBackgroundResource(R.drawable.tab_bg_image);
        }
        if (text.equals("Recetas")) {
            iv.setBackgroundResource(R.drawable.tab_bg_image1);
        }
        if (text.equals("Favoritos")) {
            iv.setBackgroundResource(R.drawable.tab_bg_image2);
        }
        if (text.equals("Mas")) {
            iv.setBackgroundResource(R.drawable.tab_bg_image3);
        }

        tv.setText(text);
        return view;
    }
}

//第一个选项卡活动在这里定义

public class FirstTab extends ActivityGroup{
    public static FirstTab group_FirstTab;

    private  ArrayList<View> history = new ArrayList<View>();
    ProgressDialog PD;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        group_FirstTab = this;
        View view = getLocalActivityManager().startActivity("CitiesAct", new
                Intent(FirstTab.this,Inicio.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView();
        replaceView(view);
    }
    public void replaceView(View view) {  

          history.add(view);
          setContentView(view);

      }
    public void RemoveView(){
         history.clear();

    }
    public void back(){
          if(history.size() > 1) {  
              history.remove(history.size()-1);  
              setContentView(history.get(history.size()-1));

          }else{
              finish();
          }
      }

     public boolean onKeyDown(int keyCode, KeyEvent event)
     {              
            if(keyCode == KeyEvent.KEYCODE_BACK){                   
                group_FirstTab.back();
                    return true;
            }
            return super.onKeyDown(keyCode, event);
     }


}

类似的有另一个选项卡活动..现在你想去意图一个选项卡到另一个选项卡活动到另一个选项卡活动下面的代码跟随

对于 ex 想要将 0 标签活动转到 1 标签活动,然后使用

tab activity Class tab_0{
    ConcinaPeruTabbar.tabHost.setCurrentTab(1); 
}

如果您想将一个选项卡活动转到 simaar 选项卡活动,请使用此视图视图 =

  FirstTab.group_FirstTab.getLocalActivityManager().startActivity("CitiesAct", new         Intent(Inicio.this,Platos.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP).putExtra("platos", "Entradas")).getDecorView();
                    FirstTab.group_FirstTab.replaceView(view);
于 2012-07-14T05:53:43.983 回答
1

如果您已经实现了一个标签栏,那么您就有一个 Activity——我们称之为 MyTabActivity——它扩展了 TabActivity。在OnCreate(Bundle)此 Activity 的方法中,您首先通过在 XML 中检索 TabHost 视图来设置您的标签栏:

TabHost tabHost = (TabHost) findViewById(R.id.tabhost);

要动态处理选项卡选择,您可以将对 TabHost 的引用保留为静态变量:

public static final TabHost tabHost;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tabActivityLayout);
    tabHost = (TabHost) findViewById(R.id.tabhost);
    // ..... 
}

然后,您可以从选项卡活动之一访问您的 TabHost,并将当前选项卡设置如下:

MyTabActivity.tabHost.setCurrentTabByTag("the tag you affected to this activity");

或者

MyTabActivity.tabHost.setCurrentTabByTag("the id you may have affected to it");

编辑:当影响标签到 TabHost 时,您会影响标签,如下所示:

TabHost.TabSpec tabSpec = tabHost.newTabSpec("The Tag").setIndicator(tabView).setContent(intent);
tabHost.addTab(tabSpec);
于 2012-07-13T21:36:18.757 回答
0

您应该使用片段在许多活动之间共享部分 UI。

于 2012-07-13T20:48:44.000 回答