添加到viewpager标签 [英] add viewpager to tabs

查看:218
本文介绍了添加到viewpager标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我这边有code。与选项卡,当你选择每个选项卡,但我不能刷卡去下一个标签它的工作原理。结果
每个标签都有列表视图有其自身的activity.Only的事情我想是添加滑动手势转到下一个tab.How做呢?我提前真的AP preciate任何help.Thanks。

 公共类AndroidTabAndListView扩展TabActivity {
    //则tabspec名称
    私有静态最后弦乐INBOX_SPEC =收件箱;
    私有静态最后弦乐OUTBOX_SPEC =发件箱;
    私有静态最后弦乐PROFILE_SPEC =档案;    ViewPager寻呼机;    @覆盖
    公共无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);
           寻呼机=(ViewPager)findViewById(R.id.pager);        TabHost tabHost = getTabHost();        //收件箱标签
        则tabspec inboxSpec = tabHost.newTabSpec(INBOX_SPEC);
        //选项卡图标
        inboxSpec.setIndicator(INBOX_SPEC,getResources()getDrawable(R.drawable.icon_inbox));
        意图inboxIntent =新意图(这一点,InboxActivity.class);
        //标签内容
        inboxSpec.setContent(inboxIntent);        //发件箱标签
        则tabspec outboxSpec = tabHost.newTabSpec(OUTBOX_SPEC);
        outboxSpec.setIndicator(OUTBOX_SPEC,getResources()getDrawable(R.drawable.icon_outbox));
        意图outboxIntent =新意图(这一点,OutboxActivity.class);
        outboxSpec.setContent(outboxIntent);        //配置文件选项卡
        则tabspec profileSpec = tabHost.newTabSpec(PROFILE_SPEC);
        profileSpec.setIndicator(PROFILE_SPEC,getResources()getDrawable(R.drawable.icon_profile));
        意图profileIntent =新意图(这一点,ProfileActivity.class);
        profileSpec.setContent(profileIntent);        //添加所有要则tabspec TabHost
        tabHost.addTab(inboxSpec); //添加收件箱标签
        tabHost.addTab(outboxSpec); //添加发件箱标签
        tabHost.addTab(profileSpec); //添加配置文件选项卡
    }
}

XML

 <?XML版本=1.0编码=UTF-8&GT?;
< TabHost的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:ID =@机器人:ID / tabhost
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT>    <的LinearLayout
        机器人:layout_width =FILL_PARENT
        机器人:layout_height =409dp
        机器人:方向=垂直>        < TabWidget
            机器人:ID =@机器人:ID /标签
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =WRAP_CONTENT/>
        <的FrameLayout
            机器人:ID =@机器人:ID / tabcontent
            机器人:layout_width =FILL_PARENT
            机器人:layout_height =FILL_PARENT>
            < android.support.v4.view.ViewPager
        机器人:ID =@ + ID /寻呼机
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent/>
            < /&的FrameLayout GT;    < / LinearLayout中>
< / TabHost>


解决方案

奥莱特我看你不使用 ViewPager 中的XML。因为我还没有尝试过你是干什么的方式,我建议,如果你不喜欢它下面的例子将是一个容易得多:结果
创建具有标签结果刷卡次数
的Andr​​oid Tab键布局与滑动式景观搜索结果
还没有用,那么你可以读<一个href=\"http://stackoverflow.com/questions/15804949/swipe-with-tab-host/15805156#15805156\">this

希望它可以帮助你。干杯:)

I have the code here with tabs and It works when you select each tab but I cannot swipe to go to next tab.
Each tab has listview which has its own activity.Only thing I want is to add swipe gesture to go to next tab.How do I do that? I really appreciate any help.Thanks in Advance.

public class AndroidTabAndListView extends TabActivity {
    // TabSpec Names
    private static final String INBOX_SPEC = "Inbox";
    private static final String OUTBOX_SPEC = "Outbox";
    private static final String PROFILE_SPEC = "Profile";

    ViewPager pager;



    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);


           pager = (ViewPager) findViewById(R.id.pager);

        TabHost tabHost = getTabHost();

        // Inbox Tab
        TabSpec inboxSpec = tabHost.newTabSpec(INBOX_SPEC);
        // Tab Icon
        inboxSpec.setIndicator(INBOX_SPEC, getResources().getDrawable(R.drawable.icon_inbox));
        Intent inboxIntent = new Intent(this, InboxActivity.class);
        // Tab Content
        inboxSpec.setContent(inboxIntent);

        // Outbox Tab
        TabSpec outboxSpec = tabHost.newTabSpec(OUTBOX_SPEC);
        outboxSpec.setIndicator(OUTBOX_SPEC, getResources().getDrawable(R.drawable.icon_outbox));
        Intent outboxIntent = new Intent(this, OutboxActivity.class);
        outboxSpec.setContent(outboxIntent);

        // Profile Tab
        TabSpec profileSpec = tabHost.newTabSpec(PROFILE_SPEC);
        profileSpec.setIndicator(PROFILE_SPEC, getResources().getDrawable(R.drawable.icon_profile));
        Intent profileIntent = new Intent(this, ProfileActivity.class);
        profileSpec.setContent(profileIntent);

        // Adding all TabSpec to TabHost
        tabHost.addTab(inboxSpec); // Adding Inbox tab
        tabHost.addTab(outboxSpec); // Adding Outbox tab
        tabHost.addTab(profileSpec); // Adding Profile 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:layout_width="fill_parent"
        android:layout_height="409dp"
        android:orientation="vertical" >

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
            </FrameLayout>



    </LinearLayout>
</TabHost>

解决方案

Allright I see that you are not using the ViewPager in the xml. Because I have not tried it the way you are doin it, I recommend it will be a lot easier if you do it like the following examples:
Creating Swipe Views with Tabs
Android Tab Layout with Swipeable Views

Still not useful then you can read this
Hope it Helps you. Cheers :)

这篇关于添加到viewpager标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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