To Pass The this ViewPagerAdapter?

There is a class
public class MainActivity extends AppCompatActivity
NavigationView implements.OnNavigationItemSelectedListener {
protected void onCreate(Bundle savedInstanceState) {
setContentView(R. layout.activity_main);

final ViewPagerAdapter adapter = new ViewPagerAdapter
(getSupportFragmentManager(), tabs.getTabCount());
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabs));

ArrayList l = new ArrayList();
// l.add("Hello!");
xadapter = new MyAdapter(this,l);


This adapter is in another package, I need this class to pass from MainActivity MainActivity

public class ViewPagerAdapter extends FragmentPagerAdapter {
int mNumOfTabs;
MyAdapter xadapter;

public ViewPagerAdapter(FragmentManager fm, int NumOfTabs) {
this.mNumOfTabs = NumOfTabs;

public Fragment getItem(int position) {

switch (position) {
case 0:
OneFragment tab1 = new OneFragment();
tab1.act = MainActivity.this;
tab1.adapter = xadapter;

return tab1;
case 1:
TwoFragment tab2 = new TwoFragment();
tab2.act = MainActivity.this;
tab2.adapter = xadapter;
return tab2;
return null;

July 4th 19 at 23:33
0 answer

Find more questions by tags Android