当我尝试调用此方法“ setupWithViewPager()”时,我没有找到它

时间:2018-07-21 13:10:25

标签: java android android-viewpager android-tablayout

在父类中,因为父类是从LinearLayout扩展而来的,此函数在类Horizo​​ntalScrollView中,我该如何解决此问题

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 

    ViewPager viewPager = findViewById(R.id.viewpager); 
    CategoryAdapter adapter = new CategoryAdapter(getSupportFragmentManager(), this); 
    viewPager.setAdapter(adapter); 
    TableLayout tabLayout = findViewById(R.id.tabs); 
    tabLayout.setupWithViewPager(viewPager); 
} 

1 个答案:

答案 0 :(得分:1)

此处输入简单错误:

TableLayout tabLayout = findViewById(R.id.tabs); 

应该是:

TabLayout tabLayout = findViewById(R.id.tabs);