我创建了3个片段并将其设置在ViewPager,
中但是当我到 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
List<Fragment> fragments=new Vector<>();
fragments.add(Fragment.instantiate(this,Discover.class.getName()));
fragments.add(Fragment.instantiate(this,Category.class.getName()));
fragments.add(Fragment.instantiate(this,Favory.class.getName()));
PagerAdapter pageAdapter=new PagerAdapter(getSupportFragmentManager(),fragments);
final ViewPager viewpager=(ViewPager) findViewById(R.id.viewpager);
viewpager.setAdapter(pageAdapter);
final ActionBar actionBar =getSupportActionBar();
actionBar.setStackedBackgroundDrawable(new ColorDrawable(Color.parseColor("#EFEBE9")));
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.TabListener tabListener =new ActionBar.TabListener(){
@Override
public void onTabSelected(ActionBar.Tab tab, FragmentTransaction ft){
viewpager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction ft){
}
@Override
public void onTabReselected(ActionBar.Tab tab, FragmentTransaction ft){
}
};
TextView tD = new TextView(getApplicationContext());
tD.setText("Discover");
tD.setTextColor(Color.BLACK);
TextView tF = new TextView(getApplicationContext());
tF.setText("Favory");
tF.setTextColor(Color.BLACK);
TextView tC = new TextView(getApplicationContext());
tC.setText("Category");
tC.setTextColor(Color.BLACK);
actionBar.addTab(actionBar.newTab().setTabListener(tabListener).setCustomView(tD));
actionBar.addTab(actionBar.newTab().setTabListener(tabListener).setCustomView(tC));
actionBar.addTab(actionBar.newTab().setTabListener(tabListener).setCustomView(tF));
viewpager.addOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
@Override
public void onPageSelected(int position){
actionBar.setSelectedNavigationItem(position);
}
});
的末尾时,第一个重新加载!
onOptionsItemSelected()
答案 0 :(得分:0)
"eventDataLoader": {
"url": "data/MSFT_events.csv",
"format": "csv",
"showCurtain": true,
"showErrors": true,
"async": true,
"reverse": true,
"delimiter": ",",
"useColumnNames": true,
"postProcess": function ( data ) {
for ( var x in data ) {
switch( data[x].Type ) {
case 'A':
var color = "#85CDE6";
break;
default:
var color = "#cccccc";
break;
}
data[x].Description = data[x].Description.replace( "Upgrade", "<strong style=\"color: #0c0\">Upgrade</strong>" ).replace( "Downgrade", "<strong style=\"color: #c00\">Downgrade</strong>" );
data[x] = {
type: "pin",
graph: "g1",
backgroundColor: color,
date: data[x].Date,
text: data[x].Type,
description: "<strong>" + data[x].Title + "</strong><br />" + data[x].Description
};
}
return data;
}
}
NO_OF_FRAGMENTS_IN_MEMORY是当前视图寻呼机片段左右的片段。因此,将屏幕页面限制设置为2.还要确保在适配器中getItem方法不直接创建实例。检查它是否为null然后实例化。 `
viewPager.setOffscreenPageLimit(NO_OF_FRAGMENTS_IN_MEMORY);
`