To Pass The MainActivity.in this ViewPagerAdapter?

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

final ViewPagerAdapter adapter = new ViewPagerAdapter
(getSupportFragmentManager(), tabs.getTabCount());
viewPager.setAdapter(adapter);
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) {
super(fm);
this.mNumOfTabs = NumOfTabs;
}

@Override
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;
default:
return null;
}
}




}
July 4th 19 at 23:33
0 answer

Find more questions by tags Android