在标签主机Android开放子活动 [英] Open child activity in Tab host android

查看:105
本文介绍了在标签主机Android开放子活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我Tab_Bar.class下定义标签 我怎样才能打开孩子的活动

My Tab_Bar.class define define Tabs How I can open child activity

我使用的只有一个选项卡主机单Tab_bar.class

I am using only one single Tab_bar.class for Tab Host

public class Tab_Bar extends TabActivity  {

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab);
    setTabs() ;

}
 void setTabs()
{
    addTab("My Profile", R.drawable.home_normal, MyProfile.class);
    addTab("Search", R.drawable.search_normal, JobSearch.class);

    addTab("Saved Jobs", R.drawable.starred, Saved_jobs.class);
    addTab("Job Alert", R.drawable.job_match, JobAlert.class);
}

private void addTab(String labelId, int drawableId, Class<?> c)
{
    TabHost tabHost = getTabHost();
    Intent intent = new Intent(this, c);
    TabHost.TabSpec spec = tabHost.newTabSpec("tab" + labelId); 

    View tabIndicator = LayoutInflater.from(this).inflate(R.layout.tab_indicator, getTabWidget(), false);
    TextView title = (TextView) tabIndicator.findViewById(R.id.title);
    title.setText(labelId);
    ImageView icon = (ImageView) tabIndicator.findViewById(R.id.icon);
    icon.setImageResource(drawableId);

    spec.setIndicator(tabIndicator);
    spec.setContent(intent);
    tabHost.addTab(spec);
    tabHost.setCurrentTab(1);

}

}

我使用这些XML文件 TabIndicator.xml

I am using these xml file TabIndicator.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="0dip"
android:layout_height="55dip"    
android:layout_weight="1"
android:orientation="vertical"

 android:background="@drawable/tab_indicator"
android:padding="5dp">

<ImageView android:id="@+id/icon"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:src="@drawable/icon"

/> 

 <TextView android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true"
    style="?android:attr/tabWidgetStyle"
    android:textSize="13sp"

/>    

和Tab.xml

<?xml version="1.0" encoding="utf-8"?>

<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
    android:layout_width="fill_parent" android:layout_height="fill_parent">
    <FrameLayout android:id="@android:id/tabcontent"
        android:layout_width="fill_parent" android:layout_height="0dip"
        android:layout_weight="1" />

    <TabWidget android:id="@android:id/tabs"
        android:layout_width="fill_parent"    android:layout_height="wrap_content"
        android:layout_weight="0"  />
</LinearLayout>
</TabHost> 

我使用Tab_bar.class和标签主机这些XML文件,但我不能有关于开放任何想法 标签主机子活动。 我是新的机器人。 请帮帮我,我怎么能打开子活动 任何帮助鸭preciated

I am using Tab_bar.class and these xml file for Tab host but i can't have any idea about open tab host child activity . I am new in android. Please Help me, How i can open child activity Any Help is Appreciated

和我真的很抱歉我的英语不好

And I am really sorry about my bad English

推荐答案

这是不是eaxctly你所需要的,但可能的帮助。我用这个设置来创建动态选项卡,然后做不同的事情与他们。

This is not eaxctly what you need, but might help. I used this setup to create dynamic tabs and then do different things with them.

protected void onCreate(Bundle savedInstanceState) {
...

    final TabHost Tabs = (TabHost) findViewById(android.R.id.tabhost);
    Tabs.setup();
    int count;
        for (count =0;count < 2;count++){

            ...

            final int passedTabId = count; 
            NewTab.setContent(new TabHost.TabContentFactory()
            {
                public View createTabContent(String tag)
                {

                   ...

                 RelativeLayout layout = new RelativeLayout(getApplicationContext);
                android.widget.RelativeLayout.LayoutParams params = 
                    new RelativeLayout.LayoutParams(
                LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
                layout.setLayoutParams(params);
                layout.setId(some ID);
                layout.setBackgroundResource(R.drawable.room_background);

                   TextView dynText = new TextView(getApplicationContext);
                    ...
                   layout.addView(dynText);


                   return layout;

    // You can set onClickListeners, etc here and then assign them some functions you need
 // You can also create different layouts for every tab according to the passedTabId
                }

            });

            Tabs.addTab(NewTab);
        }
}

事情是,你不能只是简单的设置其它活动在每个选项卡中运行。您需要设置您需要您在该选项卡中创建对象的某些功能,但主要的活动是相同的。祝你好运:)

Thing is, you cant just simply set another activity to run in each tab. You need to set some functions you need to the objects you create in that tab, but the main activity remains the same. Good luck :)

这篇关于在标签主机Android开放子活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆