最初我的想法是使用选项卡式活动创建一个儿童列表。1-父母有一个或多个孩子。2-使用 volley 我想通过使用选项卡式活动的逻辑来管理为每个孩子本身创建一个新片段。
我试过了,你可以在下面看到我的活动,然后你会看到我的适配器:
private ViewPager mViewPager = null;
private ChildAdapter pagerAdapter = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_child);
// Set up the ViewPager with the sections adapter.
pagerAdapter = new ChildAdapter();
mViewPager = (ViewPager) findViewById(R.id.view_pager);
mViewPager.setAdapter(pagerAdapter);
LayoutInflater inflater = context.getLayoutInflater();
FrameLayout v0 = (FrameLayout) inflater.inflate(R.layout.fragment_profile, null);
pagerAdapter.addView(v0, 0);
}
//-----------------------------------------------------------------------------
// Here's what the app should do to add a view to the ViewPager.
public void addView(View newPage) {
int pageIndex = pagerAdapter.addView(newPage);
// You might want to make "newPage" the currently displayed page:
mViewPager.setCurrentItem(pageIndex, true);
}
//-----------------------------------------------------------------------------
// Here's what the app should do to remove a view from the ViewPager.
public void removeView(View defunctPage) {
int pageIndex = pagerAdapter.removeView(mViewPager, defunctPage);
// You might want to choose what page to display, if the current page was "defunctPage".
if (pageIndex == pagerAdapter.getCount())
pageIndex--;
mViewPager.setCurrentItem(pageIndex);
}
//-----------------------------------------------------------------------------
// Here's what the app should do to get the currently displayed page.
public View getCurrentPage() {
return pagerAdapter.getView(mViewPager.getCurrentItem());
}
//-----------------------------------------------------------------------------
// Here's what the app should do to set the currently displayed page. "pageToShow" must
// currently be in the adapter, or this will crash.
public void setCurrentPage(View pageToShow) {
mViewPager.setCurrentItem(pagerAdapter.getItemPosition(pageToShow), true);
}
}
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------