Search in sources :

Example 11 with SmartViewHolder

use of com.scwang.refreshlayout.adapter.SmartViewHolder in project SmartRefreshLayout by scwang90.

the class NestedLayoutExampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_example_region);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }
    View view = findViewById(R.id.recyclerView);
    if (view instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) view;
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
        recyclerView.setAdapter(new BaseRecyclerAdapter<String>(Arrays.asList(provinces), android.R.layout.simple_list_item_1) {

            @Override
            protected void onBindViewHolder(SmartViewHolder holder, String model, int position) {
                holder.text(android.R.id.text1, model);
            }
        }.setOnItemClickListener(this));
    }
    /**
     * 以下代码仅仅为了演示效果而已,不是必须的
     * 关键代码在 activity_example_assign_xml 中
     */
    final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    if (isFirstEnter && refreshLayout != null) {
        isFirstEnter = false;
        // 触发上拉加载
        refreshLayout.autoRefresh();
    }
}
Also used : SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) AdapterView(android.widget.AdapterView) BaseRecyclerAdapter(com.scwang.refreshlayout.adapter.BaseRecyclerAdapter) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) Toolbar(android.support.v7.widget.Toolbar)

Example 12 with SmartViewHolder

use of com.scwang.refreshlayout.adapter.SmartViewHolder in project SmartRefreshLayout by scwang90.

the class SnapHelperExampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_example_snaphelper);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    // 初始化列表和监听
    View view = findViewById(R.id.recyclerView);
    if (view instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) view;
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(new BaseRecyclerAdapter<Integer>(loadModels(), R.layout.listitem_example_snaphelper) {

            @Override
            protected void onBindViewHolder(SmartViewHolder holder, Integer model, int position) {
                holder.image(R.id.imageView, model);
            }
        });
        SnapHelper snapHelper = new PagerSnapHelper();
        snapHelper.attachToRecyclerView(recyclerView);
    }
}
Also used : SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) PagerSnapHelper(android.support.v7.widget.PagerSnapHelper) RecyclerView(android.support.v7.widget.RecyclerView) SnapHelper(android.support.v7.widget.SnapHelper) PagerSnapHelper(android.support.v7.widget.PagerSnapHelper) Toolbar(android.support.v7.widget.Toolbar)

Example 13 with SmartViewHolder

use of com.scwang.refreshlayout.adapter.SmartViewHolder in project SmartRefreshLayout by scwang90.

the class BezierRadarStyleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_style_bezier);
    mToolbar = (Toolbar) findViewById(R.id.toolbar);
    mToolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    mRefreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    mRefreshHeader = (BezierRadarHeader) findViewById(R.id.header);
    if (isFirstEnter) {
        isFirstEnter = false;
        // 第一次进入触发自动刷新,演示效果
        mRefreshLayout.autoRefresh();
    }
    View view = findViewById(R.id.recyclerView);
    if (view instanceof RecyclerView) {
        RecyclerView recyclerView = (RecyclerView) view;
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.addItemDecoration(new DividerItemDecoration(this, VERTICAL));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(new BaseRecyclerAdapter<Item>(Arrays.asList(Item.values()), simple_list_item_2, this) {

            @Override
            protected void onBindViewHolder(SmartViewHolder holder, Item model, int position) {
                holder.text(android.R.id.text1, model.name());
                holder.text(android.R.id.text2, model.nameId);
                holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
            }
        });
    }
}
Also used : SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) RecyclerView(android.support.v7.widget.RecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DividerItemDecoration(android.support.v7.widget.DividerItemDecoration) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) AdapterView(android.widget.AdapterView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Example 14 with SmartViewHolder

use of com.scwang.refreshlayout.adapter.SmartViewHolder in project SmartRefreshLayout by scwang90.

the class BasicExampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_example_basic);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    AbsListView listView = (AbsListView) findViewById(R.id.listView);
    listView.setAdapter(mAdapter = new BaseRecyclerAdapter<Void>(simple_list_item_2) {

        @Override
        protected void onBindViewHolder(SmartViewHolder holder, Void model, int position) {
            holder.text(android.R.id.text1, getString(R.string.item_example_number_title, position));
            holder.text(android.R.id.text2, getString(R.string.item_example_number_abstract, position));
            holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
        }
    });
    mAdapter.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            BottomSheetDialog dialog = new BottomSheetDialog(BasicExampleActivity.this);
            View dialogView = View.inflate(BasicExampleActivity.this, R.layout.activity_example_basic, null);
            dialog.setContentView(dialogView);
            AbsListView listView = (AbsListView) dialogView.findViewById(R.id.listView);
            listView.setAdapter(mAdapter);
            ViewGroup parentGroup = (ViewGroup) listView.getParent();
            parentGroup.removeView(listView);
            // ViewGroup parentRoot = (ViewGroup) parentGroup.getParent();
            // parentRoot.removeView(parentGroup);
            RecyclerView recyclerView = new RecyclerView(BasicExampleActivity.this);
            recyclerView.setLayoutManager(new LinearLayoutManager(BasicExampleActivity.this));
            recyclerView.setAdapter(mAdapter);
            ((SmartRefreshLayout) parentGroup).setEnableRefresh(false);
            // ((SmartRefreshLayout) parentGroup).startNestedScroll(0);
            // ((SmartRefreshLayout) parentGroup).setEnableOverScrollDrag(false);
            ((SmartRefreshLayout) parentGroup).setRefreshContent(recyclerView);
            // parentRoot.addView(recyclerView, -1, -1);
            dialog.show();
        }
    });
    final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    // 开启自动加载功能(非必须)
    refreshLayout.setEnableAutoLoadMore(true);
    refreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh(@NonNull final RefreshLayout refreshLayout) {
            refreshLayout.getLayout().postDelayed(new Runnable() {

                @Override
                public void run() {
                    mAdapter.refresh(initData());
                    refreshLayout.finishRefresh();
                    refreshLayout.setNoMoreData(false);
                }
            }, 2000);
        }
    });
    refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {

        @Override
        public void onLoadMore(@NonNull final RefreshLayout refreshLayout) {
            refreshLayout.getLayout().postDelayed(new Runnable() {

                @Override
                public void run() {
                    if (mAdapter.getItemCount() > 30) {
                        Toast.makeText(getApplication(), "数据全部加载完毕", Toast.LENGTH_SHORT).show();
                        // 将不会再次触发加载更多事件
                        refreshLayout.finishLoadMoreWithNoMoreData();
                    } else {
                        mAdapter.loadMore(initData());
                        refreshLayout.finishLoadMore();
                    }
                }
            }, 2000);
        }
    });
    // 触发自动刷新
    refreshLayout.autoRefresh();
}
Also used : OnLoadMoreListener(com.scwang.smartrefresh.layout.listener.OnLoadMoreListener) SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) ViewGroup(android.view.ViewGroup) AbsListView(android.widget.AbsListView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) AbsListView(android.widget.AbsListView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) AdapterView(android.widget.AdapterView) BaseRecyclerAdapter(com.scwang.refreshlayout.adapter.BaseRecyclerAdapter) BottomSheetDialog(android.support.design.widget.BottomSheetDialog) SmartRefreshLayout(com.scwang.smartrefresh.layout.SmartRefreshLayout) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) OnRefreshListener(com.scwang.smartrefresh.layout.listener.OnRefreshListener) Toolbar(android.support.v7.widget.Toolbar)

Example 15 with SmartViewHolder

use of com.scwang.refreshlayout.adapter.SmartViewHolder in project SmartRefreshLayout by scwang90.

the class CustomExampleActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_example_custom);
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    ListView listView = (ListView) findViewById(R.id.listView);
    listView.setAdapter(mAdapter = new BaseRecyclerAdapter<Void>(simple_list_item_2) {

        @Override
        protected void onBindViewHolder(SmartViewHolder holder, Void model, int position) {
            holder.text(android.R.id.text1, getString(R.string.item_example_number_title, position));
            holder.text(android.R.id.text2, getString(R.string.item_example_number_abstract, position));
            holder.textColorId(android.R.id.text2, R.color.colorTextAssistant);
        }
    });
    final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    refreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh(@NonNull final RefreshLayout refreshLayout) {
            refreshLayout.getLayout().postDelayed(new Runnable() {

                @Override
                public void run() {
                    mAdapter.refresh(initData());
                    refreshLayout.finishRefresh();
                }
            }, 2000);
        }
    });
    refreshLayout.setRefreshHeader(new ClassicsHeader(this));
    refreshLayout.setHeaderHeight(60);
    // 触发自动刷新
    if (isFirstEnter) {
        isFirstEnter = false;
        refreshLayout.autoRefresh();
    } else {
        mAdapter.refresh(initData());
    }
}
Also used : ListView(android.widget.ListView) SmartViewHolder(com.scwang.refreshlayout.adapter.SmartViewHolder) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) BaseRecyclerAdapter(com.scwang.refreshlayout.adapter.BaseRecyclerAdapter) OnRefreshListener(com.scwang.smartrefresh.layout.listener.OnRefreshListener) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

View (android.view.View)29 SmartViewHolder (com.scwang.refreshlayout.adapter.SmartViewHolder)29 RecyclerView (android.support.v7.widget.RecyclerView)28 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)27 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)26 AdapterView (android.widget.AdapterView)25 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)23 Toolbar (android.support.v7.widget.Toolbar)13 RefreshLayout (com.scwang.smartrefresh.layout.api.RefreshLayout)11 BaseRecyclerAdapter (com.scwang.refreshlayout.adapter.BaseRecyclerAdapter)8 OnLoadMoreListener (com.scwang.smartrefresh.layout.listener.OnLoadMoreListener)4 OnRefreshListener (com.scwang.smartrefresh.layout.listener.OnRefreshListener)4 AppBarLayout (android.support.design.widget.AppBarLayout)3 ViewGroup (android.view.ViewGroup)3 ImageView (android.widget.ImageView)3 BottomSheetDialog (android.support.design.widget.BottomSheetDialog)2 AbsListView (android.widget.AbsListView)2 TextView (android.widget.TextView)2 R.id.recyclerView (com.scwang.refreshlayout.R.id.recyclerView)2 Item (com.scwang.refreshlayout.fragment.example.PureScrollExampleFragment.Item)2