@Override public int getCount() { if (mFragments.size() == 0) { Purchase active = new Purchase(); Cursor cursor = active.findAll( null, Purchase.COLUMN_STATUS + "=?", new String[] {Purchase.STATUS_ACTIVE}, Purchase.ORDER_DEFAULT); if (cursor != null & cursor.getCount() > 0) { do { BasePageFragment fragment = new PageFragment(); Purchase purchase = new Purchase(cursor); // Передача параметров Bundle bundle = new Bundle(); bundle.putParcelable(Purchase.PARCELABLE_NAME, purchase); fragment.setArguments(bundle); // Добавить в список фрагментов mFragments.add(fragment); mIds.add(purchase.getID()); } while (cursor.moveToNext()); } else { // Пустой список BasePageFragment fragment = new AddPageFragment(); mFragments.add(fragment); mIds.add(null); } } return mFragments.size(); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { mPurchase = savedInstanceState.getParcelable(Purchase.PARCELABLE_NAME); } else if (getArguments() != null) { mPurchase = getArguments().getParcelable(Purchase.PARCELABLE_NAME); } else { mPurchase = new Purchase(); } setTitle(mPurchase.getName()); // Размещаем виджеты FragmentManager fragmentManager = getChildFragmentManager(); mWidgets = new ArrayList<Widget>(); Summary summary = new Summary(); mWidgets.add(summary); List list = new List(); mWidgets.add(list); fragmentManager .beginTransaction() .replace(R.id.summary_container, summary) .replace(R.id.list_container, list) .commit(); }
/** * Обновить все виджеты * * @param source */ public void onDataSetChanged(Widget source) { mPurchase.refresh(); for (Widget w : mWidgets) { if (source == null || source != w) { w.onDataSetChanged(); } } }