android this view's id is no_id,在对话框安卓中,在添加标签时出现'No view found for id'异常_android_开发99编程知识库...

我有一个 Activity,我想用 2个标签显示一个对话框。 我在按钮单击上有下面的代码,它将显示对话框:Dialog dialog = new Dialog(this);

//select_category is having ViewPager and TabLayout inside of a Framelayout

dialog.setContentView(R.layout.select_category);

ViewPager objViewPager = (ViewPager) dialog.findViewById(R.id.viewPager);

objViewPager.setAdapter(new MyTabsAdapter(getSupportFragmentManager()));

TabLayout mTabLayout = (TabLayout) dialog.findViewById(R.id.tabLayout);

mTabLayout.setTabTextColors(getResources().getColorStateList(R.color.tabcolors));

mTabLayout.setupWithViewPager(objViewPager);

dialog.show();

ViewPager的Adaper为,public class MyTabsAdapter extends FragmentPagerAdapter {

String[] tabs = {"FIRST","SECOND"};

public MyTabsAdapter(FragmentManager fm) {

super(fm);

}

@Override

public Fragment getItem(int position) {

switch (position) {

case 0: {

//for now, returning plain fragment for simplicity

return new Fragment();

}

case 1: {

return new Fragment();

}

default:

return null;

}

}

}

select_category.xml 是

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:background="@color/background"

android:theme="@style/NoActionBarTheme">

android:id="@+id/viewPager"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:layout_marginTop="@dimen/view_pager_top_margin"/>

android:id="@+id/tabLayout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@color/primary"/>

当我运行这个代码时,我得到的是 IllegalArgumentException,java.lang.IllegalArgumentException: 没有找到用于 fragment fragment的id 0 x7f0a00da ( 。com: id/viewpager )的视图

我正在使用的TabLayout来自google支持库的设计( android.support.design.widget.TabLayout ) 。

我不知道我在哪里出错。 请帮助任何教程/指南建议都会被推荐。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值