首先我使用了FragmentPagerAdapter,我曾经使用它来获取当前的viewpager,但由于我有两个实现了viewpager的片段,它与其他的冲突,而不是我切换到FragmentStatePagerAdapter解决了冲突,但是当我试图获取当前的viewpager时返回null
getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.pager + ":" + viewPager.getCurrentItem())
SalesReport extends Fragment
final ViewPager viewPager = (ViewPager) viewGroup.findViewById(R.id.pager);
TabsPagerAdapter adapter = new TabsPagerAdapter(myContext.getSupportFragmentManager());
viewPager.setAdapter(adapter);
TabLayout tabLayout = (TabLayout) viewGroup.findViewById(R.id.sliding_tabs);
tabLayout.setupWithViewPager(viewPager);
TextView quantity = (TextView) viewGroup.findViewById(R.id.quantity);
quantity.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
quantityBoolean = !quantityBoolean;
SalesReportList page = (SalesReportList) myContext.getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.pager + ":" + viewPager.getCurrentItem());
ListView listView = (ListView) page.getView().findViewById(R.id.saleslistview);
SalesReportItemAdapter adapter = (SalesReportItemAdapter) listView.getAdapter();
adapter.sortquantiy(quantityBoolean);
}
});
TabsPagerAdapter extends FragmentStatePagerAdapter{
@Override
public Fragment getItem(int position) {
return new SalesReportList().newInstance(position);
}
}
class SalesReportList extends Fragment
ViewGroup viewGroup = (ViewGroup) inflater.inflate(R.layout.fragment_sales_report_list, container, false);
ListView listView = (ListView) viewGroup.findViewById(R.id.saleslistview);
SalesReportItemAdapter listItemAdapter = new SalesReportItemAdapter(this, productType);
listView.setAdapter(listItemAdapter);
class SalesReportItemAdapter extends BaseAdapter
Fragment context;
ProductType productType;
List<Sales> salesList;
public SalesReportItemAdapter(Fragment salesReportList, ProductType productType) {
context = salesReportList;
this.productType = productType;
salesList = Myenum.INSTANCE.getSalesList(productType);
}
使用FragmentStatePagerAdapter
返回null答案 0 :(得分:2)
library(reshape2); library(plyr); library(stringr); library(lubridate);
library(knitr); library(sp); library(rgeos); library(lme4); library(formatR);
library(rgdal); library(ggmap); library(maptools); library(Hmisc); library(raster);
library(car); library(extrafont); library(openNLP); library(effects); library(psych);
library(MuMIn); library(GPArotation); library(tuneR); library(gdata); library(xlsx);
library(combinat); library(stargazer); library(grid); library(scales); library(dplyr);
library(english); library(repmis); library(pscl); library(testthat); library(broom);
library(ggplot2); library(geosphere); library(moult); library(GGally); library(pavo);
library(stringi); library(mgcv); library(gam)
detach(package:car, unload = TRUE)
detach(package:mgcv, unload = TRUE)
if (require("gam", quietly = TRUE)) {
data(kyphosis)
g <- gam::gam(Kyphosis ~ s(Age,4) + Number, family = binomial, data = kyphosis)
tidy(g)
augment(g)
glance(g)
}
Warning: namespace ‘mgcv’ is not available and has been replaced
by .GlobalEnv when processing object ‘kyphosis’
Warning: namespace ‘mgcv’ is not available and has been replaced
by .GlobalEnv when processing object ‘kyphosis’
Warning: namespace ‘mgcv’ is not available and has been replaced
by .GlobalEnv when processing object ‘kyphosis’
Warning: namespace ‘mgcv’ is not available and has been replaced
by .GlobalEnv when processing object ‘kyphosis’
Warning: namespace ‘mgcv’ is not available and has been replaced
by .GlobalEnv when processing object ‘kyphosis’
Warning: namespace ‘mgcv’ is not available and has been replaced
by .GlobalEnv when processing object ‘kyphosis’
Error in `$<-.data.frame`(`*tmp*`, "logLik", value = numeric(0)) :
replacement has 0 rows, data has 1