我必须制作包含3个活动的项目。第1和第2活动包含2个选项卡,第3活动需要3个选项卡。我是否需要为每项活动制作3个Pager条款?或者,如果One Pager.class可以处理所有选项卡,那么我们如何对其进行排序? 感谢所有提前!
答案 0 :(得分:0)
您可以使用同一个班级。只需确保被覆盖的方法可以区分它所处的活动。因此getCount()
中的FragmentPagerAdapter
作为示例会在第1和第2个活动中返回2,但在第3个活动中返回3个。布局也是如此。
答案 1 :(得分:0)
是的,您可以为每个活动使用此pageradapter类。它将在活动中创建您想要的大小
workspace = c:\tools\jenkins\workspace\PerformanceTesting
[Pipeline] echo
env.WORKSPACE = c:\tools\jenkins\workspace\PerformanceTesting
[Pipeline] step
Archiving artifacts
Recording fingerprints
[Pipeline] step
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
java.io.FileNotFoundException: c:\tools\jenkins\workspace\PerformanceTesting\jmeter_scripts\jenkins_test_results.jtl (The system cannot find the path specified)
at java.io.FileInputStream.open0(Native Method)
at java.io.FileInputStream.open(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileReader.<init>(Unknown Source)
at hudson.plugins.performance.parsers.ParserDetector.detect(ParserDetector.java:21)
at hudson.plugins.performance.parsers.ParserFactory.getParser(ParserFactory.java:26)
at hudson.plugins.performance.PerformancePublisher.getParsers(PerformancePublisher.java:439)
at hudson.plugins.performance.PerformancePublisher.perform(PerformancePublisher.java:481)
at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:69)
at org.jenkinsci.plugins.workflow.steps.CoreStep$Execution.run(CoreStep.java:59)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1$1.call(AbstractSynchronousNonBlockingStepExecution.java:52)
at hudson.security.ACL.impersonate(ACL.java:221)
at org.jenkinsci.plugins.workflow.steps.AbstractSynchronousNonBlockingStepExecution$1.run(AbstractSynchronousNonBlockingStepExecution.java:49)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Finished: FAILURE
答案 2 :(得分:0)
您可以使用相同的PagerAdapter
课程。以下是PagerAdapter
示例。
<强> TabsPagerAdapter.java 强>
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import java.util.ArrayList;
import java.util.List;
public class TabsPagerAdapter extends FragmentPagerAdapter {
private final List<Fragment> mFragmentList = new ArrayList<>();
private final List<String> mFragmentTitleList = new ArrayList<>();
public TabsPagerAdapter(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);
}
}
来自FirstActivity.java
:
TabLayout mTabLayout;
ViewPager mViewPager;
TabsPagerAdapte mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
// Tab layout
mTabLayout = (TabLayout) findViewById(R.id.tabs);
// View pager
mViewPager = (ViewPager) findViewById(R.id.view_pager);
// Adapter
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
// 2 Tabs
mAdapter.addFrag(new FragmentOne(), "ONE");
mAdapter.addFrag(new FragmentTwo(), "TWO");
mViewPager.setAdapter(mAdapter);
mTabLayout.setupWithViewPager(mViewPager);
mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
来自SecondActivity.java
:
TabLayout mTabLayout;
ViewPager mViewPager;
TabsPagerAdapte mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
// Tab layout
mTabLayout = (TabLayout) findViewById(R.id.tabs);
// View pager
mViewPager = (ViewPager) findViewById(R.id.view_pager);
// Adapter
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
// 2 Tabs
mAdapter.addFrag(new FragmentOne(), "ONE");
mAdapter.addFrag(new FragmentTwo(), "TWO");
mViewPager.setAdapter(mAdapter);
mTabLayout.setupWithViewPager(mViewPager);
mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
来自ThirdActivity.java
:
TabLayout mTabLayout;
ViewPager mViewPager;
TabsPagerAdapte mAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_third);
// Tab layout
mTabLayout = (TabLayout) findViewById(R.id.tabs);
// View pager
mViewPager = (ViewPager) findViewById(R.id.view_pager);
// Adapter
mAdapter = new TabsPagerAdapter(getSupportFragmentManager());
// 3 Tabs
mAdapter.addFrag(new FragmentOne(), "ONE");
mAdapter.addFrag(new FragmentTwo(), "TWO");
mAdapter.addFrag(new FragmentThree(), "THREE");
mViewPager.setAdapter(mAdapter);
mTabLayout.setupWithViewPager(mViewPager);
mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
mViewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
希望这会有所帮助〜