Search in sources :

Example 1 with DataBean

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;
}
Also used : Context(android.content.Context) GridLayoutManager(android.support.v7.widget.GridLayoutManager) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) ArrayList(java.util.ArrayList) RecyclerView(android.support.v7.widget.RecyclerView) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) SwipeRefreshLayout(android.support.v4.widget.SwipeRefreshLayout) DataBean(com.example.fj.second.model.DataBean) MyItemRecyclerViewAdapter(com.example.fj.second.adapter.MyItemRecyclerViewAdapter)

Aggregations

Context (android.content.Context)1 SwipeRefreshLayout (android.support.v4.widget.SwipeRefreshLayout)1 GridLayoutManager (android.support.v7.widget.GridLayoutManager)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)1 View (android.view.View)1 MyItemRecyclerViewAdapter (com.example.fj.second.adapter.MyItemRecyclerViewAdapter)1 DataBean (com.example.fj.second.model.DataBean)1 ArrayList (java.util.ArrayList)1