Skip to content

Instantly share code, notes, and snippets.

@communikein
Last active January 16, 2018 14:27
Show Gist options
  • Save communikein/7b5ac7c3b55be42fe39dfb52f38476a3 to your computer and use it in GitHub Desktop.
Save communikein/7b5ac7c3b55be42fe39dfb52f38476a3 to your computer and use it in GitHub Desktop.
public class PoisListFragment extends Fragment implements {
private AcFragmentPoisListBinding mBinding;
private PoisListAdapter mAdapter;
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
/* Inflate the layout for this fragment */
mBinding = DataBindingUtil.inflate(inflater, R.layout.ac_fragment_pois_list, container, false);
LinearLayoutManager layoutManager = new LinearLayoutManager(
getActivity(),
LinearLayoutManager.VERTICAL,
false);
mBinding.listRecyclerview.setLayoutManager(layoutManager);
mBinding.listRecyclerview.setHasFixedSize(true);
return mBinding.getRoot();
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mAdapter = new PoisListAdapter(this);
mBinding.listRecyclerview.setAdapter(mAdapter);
if (getParentViewModel() != null) {
getParentViewModel().getObservableAllPois().observe(this, list -> {
if (list != null) {
Log.d(LOG_TAG, "New data received. Size: " + list.size());
mAdapter.setList((ArrayList<Poi>) list);
}
});
}
}
private PoisViewModel getParentViewModel() {
if (getActivity() != null)
return ((MainActivity) getActivity()).getViewModel();
else
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment