use of com.example.fj.second.model.DataBean in project CoordinatorLayoutDemo by JamFF.
the class ItemFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_item_list, container, false);
View list = view.findViewById(R.id.list);
if (view instanceof SwipeRefreshLayout) {
mRefreshLayout = (SwipeRefreshLayout) view;
mRefreshLayout.setOnRefreshListener(this);
mRefreshLayout.setColorSchemeColors(Color.BLUE, Color.GREEN, Color.BLACK);
}
if (list instanceof RecyclerView) {
// Set RecyclerView adapter
Context context = view.getContext();
RecyclerView recyclerView = (RecyclerView) list;
List<DataBean> beanList = new ArrayList<>();
if (mOrientation != LinearLayout.VERTICAL && mOrientation != LinearLayout.HORIZONTAL) {
mOrientation = LinearLayout.VERTICAL;
}
if (mColumnCount <= 1) {
mColumnCount = 1;
recyclerView.setLayoutManager(new LinearLayoutManager(context, mOrientation, mReverseLayout));
for (int i = 0; i < DATAS.ICONS.length; i++) {
DataBean bean = new DataBean();
bean.setIcon(DATAS.ICONS[i]);
bean.setName("图片-" + i);
beanList.add(bean);
}
} else {
if (mStaggered) {
StaggeredGridLayoutManager layoutManager = new StaggeredGridLayoutManager(mColumnCount, mOrientation);
layoutManager.setReverseLayout(mReverseLayout);
recyclerView.setLayoutManager(layoutManager);
for (int i = 0; i < DATAS.PICS.length; i++) {
DataBean bean = new DataBean();
bean.setIcon(DATAS.PICS[i]);
bean.setName("图片-" + i);
beanList.add(bean);
}
} else {
recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount, mOrientation, mReverseLayout));
for (int i = 0; i < DATAS.ICONS.length; i++) {
DataBean bean = new DataBean();
bean.setIcon(DATAS.ICONS[i]);
bean.setName("图片-" + i);
beanList.add(bean);
}
}
}
recyclerView.setAdapter(new MyItemRecyclerViewAdapter(beanList, mColumnCount, mListener));
}
return view;
}
Aggregations