最近做项目遇到这样一个需求,就是TabHost中的某一个选项卡内多个页面来回切换的问题,但是自己试了一下,好像不太好做,还要请教有经验的高手指点一下。有哪位高人做过类似的项目也可以指点指点。

解决方案 »

  1.   


     这是我学习的TabHost 看看有没有帮助package com.souba.main;import android.app.TabActivity;  
    import android.os.Bundle;  
    import android.view.View;  
    import android.widget.Button;  
    import android.widget.EditText;  
    import android.widget.TabHost;  
    import android.widget.TabHost.TabSpec;  
    public class MainActivity extends TabActivity {//基于TabActivity构建  
          
        Button btnTab1,btnTab2;  
        EditText edtTab1,edtTab2;  
        /** Called when the activity is first created. */ 
        @Override 
        public void onCreate(Bundle savedInstanceState) {  
            super.onCreate(savedInstanceState);  
            setContentView(R.layout.main);  
            
            TabHost tabs = getTabHost();  
            //设置Tab1  
            TabSpec tab1 = tabs.newTabSpec("tab1");  
            tab1.setIndicator("机票");      // 设置tab1的名称  
            tab1.setContent(R.id.Tab1);    // 关联控件  
            tabs.addTab(tab1);                // 添加tab1  
              
            btnTab1=(Button)this.findViewById(R.id.btnTab1);  
            edtTab1=(EditText)this.findViewById(R.id.edtTab1);  
            btnTab1.setOnClickListener(new ClickEvent());  
              
            //设置Tab2  
            TabSpec tab2 = tabs.newTabSpec("tab2");  
            tab2.setIndicator("酒店");        
            tab2.setContent(R.id.Tab2);      
            tabs.addTab(tab2);                  
              
            btnTab2=(Button)this.findViewById(R.id.btnTab2);  
            edtTab2=(EditText)this.findViewById(R.id.edtTab2);  
            btnTab2.setOnClickListener(new ClickEvent());  
              
            tabs.setCurrentTab(0);  
        }  
          
        class ClickEvent implements View.OnClickListener {  
            @Override 
            public void onClick(View v) {  
                if(v==btnTab1)  
                {  
                    edtTab1.setText("tab1");  
                }  
                else if(v==btnTab2)  
                {  
                    edtTab2.setText("tab2");  
                }  
            }  
          
        }  
    } <?xml version="1.0" encoding="utf-8"?> 
    <TabHost android:layout_width="fill_parent" 
        android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost"> 
        <TabWidget android:id="@android:id/tabs" 
            android:layout_height="wrap_content" android:layout_width="fill_parent"> 
    </TabWidget> 
        <FrameLayout android:id="@android:id/tabcontent" 
            android:paddingTop="65px" android:layout_width="fill_parent" android:layout_height="fill_parent"> 
            <LinearLayout 
            android:layout_height="wrap_content" 
            android:id="@+id/Tab1" 
            android:orientation="vertical" 
            android:layout_width="fill_parent"> 
               <EditText 
               android:layout_height="wrap_content" 
               android:id="@+id/edtTab1" 
               android:layout_width="fill_parent">
               </EditText> 
               <Button 
               android:layout_width="wrap_content" 
               android:layout_height="wrap_content" 
               android:id="@+id/btnTab1" 
               android:text="Tab1">
               </Button> 
            </LinearLayout> 
            <LinearLayout 
            android:layout_height="wrap_content" 
            android:id="@+id/Tab2" 
            android:layout_width="fill_parent" 
            android:orientation="horizontal"> 
            <EditText 
            android:layout_height="wrap_content" 
            android:id="@+id/edtTab2" 
            android:layout_width="wrap_content" 
            android:layout_weight="300">
            </EditText> 
               <Button 
               android:layout_width="wrap_content" 
               android:layout_height="wrap_content" 
               android:id="@+id/btnTab2" android:text="Tab2">
               </Button>
            </LinearLayout> 
        </FrameLayout> 
    </TabHost>  
      

  2.   

    你是怎么切换的,多个页面切换可以用framelayout配合viewflipper来实现
      

  3.   

    也有这个需求 啊,就像是 logCat中的那些 选项卡那样 来回的切换呐   希望 高手能贴上几行参考代码啊   代楼主 深表谢意  O(∩_∩)O~
      

  4.   

    LZ 是切换布局呢 还是切换activity呢?
      

  5.   

    应该是切换布局,我也需要做这个,如果切换activity,原来的框架就没了,跳转到一个新的页面了,我们要的是在一个tab页内,实现点击几个单选按钮,切换下面的布局,请问高手怎么没解决这个问题?
      

  6.   


    TabHost  实现菜单模式,网上好多,你可以查阅一下