Closed weicheng113 closed 9 years ago
Fragment is naturally supported from the current version 0.8.5. The demo for Fragment is added to Gallery project.
The gallery app shows using the more advanced FragmentManager method, but is using simple
For instance I have a landscape layout xml that has:
<LinearLayout ...>
<fragment
...
class="com.example.MainActivity$LeftFragment/>
<fragment
...
class="com.example.MainActivity$RightFragment/>
</LinearLayout>
And in the Fragment's onCreateView
function I have:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
PresModel pm = new PresModel();
BinderFactory factory = new BinderFactoryBuilder()
.add(new DynamicViewBinding()
.forView(Switch.class)
.oneWayProperties("checked")
.oneWayProperties("enabled"))
.build();
View rootView = factory.createViewBinder(inflater.getContext())
.inflateAndBindWithoutAttachingToRoot(R.layout.fragment_left, PresModel,container);
return rootView;
}
The .inflateAndBindWithoutAttachingToRoot
function throws java.lang.NullPointerException: Root must not be null
. This function works fine in my portrait mode layout (it uses a ViewPager).
@bj0,
The container of ViewGroup is null. You will need to use viewBinder.inflateAndBind instead. You can find the example here - https://github.com/RoboBinding/Android-CleanArchitecture/blob/master/presentation/src/main/java/com/fernandocejas/android10/sample/presentation/view/fragment/UserListFragment.java
Simple fragment tag is not supported at the moment. We will add the support in future. There is a related issue here - #194 .
Actually I did get it to work with .inflateAndBind
. I put the following in onCreateView
if( container == null )
rootView = factory.createViewBinder(inflater.getContext())
.inflateAndBind(R.layout.fragment_left, PresModel);
else
rootView = factory.createViewBinder(inflater.getContext())
.inflateAndBindWithoutAttachingToRoot(R.layout.fragment_left, PresModel,container);
And it appears to be working fine now.
Fragment, ListFragment support.