开发者

android tabhost add view to the tab from another tab

开发者 https://www.devze.com 2023-03-12 17:58 出处:网络
I need little bit help related to android tabhost. I have 3 tabs and 3 activities.开发者_开发问答 MainTab activity is\"extends from TabActivity\" and other 2 activities are \"extends from Activity\".

I need little bit help related to android tabhost. I have 3 tabs and 3 activities.开发者_开发问答 MainTab activity is "extends from TabActivity" and other 2 activities are "extends from Activity".

In MainTab activity there are two buttons Radio and CheckBox, when user click radio button then i want to display radio button view in tab2. when user click check box i want to display checkbox view. Can some gives me an idea how I can achieve this?? Below is my code.

    public class MainTabHost extends TabActivity  implements OnTabChangeListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState){
    super.onCreate(savedInstanceState);
    setContentView(R.layout.homeui);

    TabHost tabHost = getTabHost(); 
    tabHost.setOnTabChangedListener(this);

    TabHost.TabSpec spec;  
    Intent intent; 

    intent = new Intent().setClass(this, Main.class);        
    spec = tabHost.newTabSpec("Main Tab").
    setIndicator("Main Tab")
                  .setContent(intent);
    spec.setIndicator("", this.getResources().getDrawable(R.drawable.maintabicon) );
    tabHost.addTab(spec);

    intent = new Intent().setClass(this, TabA.class);
    spec = tabHost.newTabSpec("Tab A").
    setIndicator("Tab A")
                  .setContent(intent);
    spec.setIndicator("", this.getResources().getDrawable(R.drawable.tabaicon) );
    tabHost.addTab(spec);


    tabHost.setCurrentTab(0);       

}

@Override
public void onTabChanged(String tabId) {

}

}


You can use SharedPreference for this. So that when you choose radio button you can change your shared value to radio and when you use Check box change value to check box and use the view in your second tab according to the shared value.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号