我想,他们中的GiPagerAdapter想到活动,不知道如何去做。 这一格式适应者。 添加Frag(新的RsFragment,“新闻”;如何改变变换者。 增加Frag(新活动,“新闻”)
`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 Adaptationer = New ViewPagerAdapter (getSupportFragmentManager()); tjis how to set activity category