Begined
2019-10-14 23:43
package info.z_pw.ebook.Activitys; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; import androidx.viewpager.widget.ViewPager; import info.z_pw.ebook.Adapters.MainViewPageAdapter; import info.z_pw.ebook.Base.BaseActivity; import info.z_pw.ebook.Events.MainPageChangeListener; import info.z_pw.ebook.R; import info.z_pw.ebook.Views.ETabWidget; import android.os.Bundle; import android.widget.ImageView; import java.util.ArrayList; import java.util.List; public class MainActivity extends BaseActivity { private ViewPager mainWindow; private ETabWidget findBtn; private ETabWidget bookBtn; private ETabWidget meBtn; private List<ETabWidget> btnList = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initView(); } private void initView() { findBtn = findViewById(R.id.tab_find); bookBtn = findViewById(R.id.tab_book); meBtn = findViewById(R.id.tab_me); mainWindow = findViewById(R.id.main_window); btnList.add(findBtn); btnList.add(bookBtn); btnList.add(meBtn); initViewPager(); } private void initViewPager() { mainWindow.setAdapter(new MainViewPageAdapter()); mainWindow.addOnPageChangeListener(new MainPageChangeListener(btnList)); } }
new MainViewPageAdapter()需要androidx.fragment.app.FragmentManager,activity怎么获取
你其中一行代码写错了,
mViewPagerMain.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {} 是 new FragmentPagerAdapter 或 FragmentStatePagerAdapter, 因为这个是适配器,如果要new 自己的,你可以重新定义一个扩展类 public class xxxxxx extends FragmentPagerAdapter{}
ViewPager+Tab特效实现微信主界面
6387 学习 · 35 问题
相似问题