答案 0 :(得分:0)
转到Adapter类并添加如下代码:
private final Activity mContext;
private final Fragment[][] mFragment;
public MyGridViewPagerAdapter(Activity ctx, FragmentManager fm, Fragment[][] fragments)
{
super(fm);
mContext = ctx;
this.mFragment = fragments;
}
然后覆盖以下方法:
@Override
public Fragment getFragment(int row, int col)
{
return mFragment[row][col];
}
@Override
public int getRowCount()
{
return mFragment.length;
}
@Override
public int getColumnCount(int rowNum)
{
return mFragment[rowNum].length;
}
然后在您的活动中执行以下操作:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
final GridViewPager pager = (GridViewPager) findViewById(R.id.pager);
final Fragment[][] items = {
{
CusmtomFragment.newInstance("your","arguments"),
CusmtomFragment.newInstance()
},
{
OtherFragment.newInstance(),
AnotherFragment.newInstance(1234)
}
};
// ....
pager.setAdapter(new MyGridViewPagerAdapter(this, getFragmentManager(), items));
}
还请检查此问题:Is there any way to detect if the clock is round?
希望它会有所帮助