I want the ViewPagerAdapter in these to go to the activity and don't know how to get it.This format adapter.addFrag(new RssFragment(), "news"); how to change convert adapter.addFrag(new activity(), "news")
`public class ScrollableTabsActivity extends AppCompatActivity {
private Toolbar toolbar;
private TabLayout tabLayout;
private ViewPager viewPager;
private AdView mAdView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_scrollable_tabs);
mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
toolbar = (Toolbar) findViewById(R.id.toolbar2);
setSupportActionBar(toolbar);
viewPager = (ViewPager) findViewById(R.id.viewpager);
setupViewPager(viewPager);
tabLayout = (TabLayout) findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
}
private void setupViewPager(ViewPager viewPager) {
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFrag(new RssFragment(), "వార్తలు");
adapter.addFrag(new RssFragment2(), "సినిమా");
adapter.addFrag(new RssFragment3(), "చదువు");
adapter.addFrag(new RssFragment4(), "జ్యోతిషశాస్త్రం");
adapter.addFrag(new RssFragment5(), "క్రీడలు");
adapter.addFrag(new RssFragment6(), "రాజకీయాలు");
adapter.addFrag(new RssFragment7(), "సాధారణ");
adapter.addFrag(new RssFragment8(), "వంటకాలు");
viewPager.setAdapter(adapter);
}
@Override
public void onBackPressed() {
new AlertDialog.Builder(this).setIcon(android.R.drawable.ic_dialog_alert).setTitle("Exit")
.setMessage("Are you sure you want to exit?")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
}).setNegativeButton("No", null).show();
}
class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public
ViewPagerAdapter(FragmentManager manager) {
super(manager);
}
@Override
public Fragment getItem(int position) {
return mFragmentList.get(position);
}
@Override
public int getCount() {
return mFragmentList.size();
}
public void addFrag(Fragment fragment, String title) {
mFragmentList.add(fragment);
mFragmentTitleList.add(title);
}
@Override
public CharSequence getPageTitle(int position) {
return mFragmentTitleList.get(position);
}
}
}
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager()); tjis how to set activity class
You can't use activity instead of fragment in ViewPagerAdapter.
In general, you can use a fragment to display a part of the user interface in an activity, but it is not possible to display another activity as part of the user interface in an activity.
Therefore, you should convert your desired activity into a Fragment.