Search in sources :

Example 16 with RefreshLayout

use of com.scwang.smartrefresh.layout.api.RefreshLayout in project EnableHands by LeviWGG.

the class PictureFragment method initView.

@Override
public void initView() {
    // List<Picture> list = new ArrayList<>();
    // for (int i = 0; i < 10; i++) {
    // list.add(new Picture(0, url, "测试标题", ""));
    // }
    smartRefreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() {

        @Override
        public void onLoadmore(RefreshLayout refreshlayout) {
            smartRefreshLayout.finishLoadmore(2000);
            mPresenter.getWeixinNews();
        }
    });
    mPresenter.getWeixinNews();
    showProgressDialog("加载中");
}
Also used : SmartRefreshLayout(com.scwang.smartrefresh.layout.SmartRefreshLayout) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) OnLoadmoreListener(com.scwang.smartrefresh.layout.listener.OnLoadmoreListener)

Example 17 with RefreshLayout

use of com.scwang.smartrefresh.layout.api.RefreshLayout in project SmartRefreshLayout by scwang90.

the class AssignDefaultExampleActivity method onCreate.

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

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    /*
         * 以下代码仅仅为了演示效果而已,不是必须的
         * 关键代码在构造函数中
         */
    final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    if (isFirstEnter) {
        isFirstEnter = false;
        // 触发上拉加载
        refreshLayout.autoLoadMore();
        // 通过多功能监听接口实现 在第一次加载完成之后 自动刷新
        refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {

            @Override
            public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
                if (oldState == RefreshState.LoadFinish && newState == RefreshState.None) {
                    refreshLayout.autoRefresh();
                    refreshLayout.setOnMultiPurposeListener(null);
                }
            }

            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                refreshLayout.finishLoadMore(2000);
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                refreshLayout.finishRefresh(3000);
            }
        });
    }
}
Also used : SimpleMultiPurposeListener(com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener) SmartRefreshLayout(com.scwang.smartrefresh.layout.SmartRefreshLayout) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) RefreshState(com.scwang.smartrefresh.layout.constant.RefreshState) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Example 18 with RefreshLayout

use of com.scwang.smartrefresh.layout.api.RefreshLayout in project SmartRefreshLayout by scwang90.

the class AssignXmlExampleActivity method onCreate.

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

        @Override
        public void onClick(View v) {
            finish();
        }
    });
    /*
         * 以下代码仅仅为了演示效果而已,不是必须的
         * 关键代码在 activity_example_assign_xml 中
         */
    final RefreshLayout refreshLayout = (RefreshLayout) findViewById(R.id.refreshLayout);
    if (isFirstEnter) {
        isFirstEnter = false;
        // 触发上拉加载
        refreshLayout.autoLoadMore(250, 250, 1.5f);
        // 通过多功能监听接口实现 在第一次加载完成之后 自动刷新
        refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener() {

            @Override
            public void onStateChanged(@NonNull RefreshLayout refreshLayout, @NonNull RefreshState oldState, @NonNull RefreshState newState) {
                if (oldState == RefreshState.LoadFinish && newState == RefreshState.None) {
                    refreshLayout.autoRefresh();
                    refreshLayout.setOnMultiPurposeListener(null);
                }
            }

            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                refreshLayout.finishLoadMore(2000);
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                refreshLayout.finishRefresh(3000);
            }
        });
    }
}
Also used : SimpleMultiPurposeListener(com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) RefreshState(com.scwang.smartrefresh.layout.constant.RefreshState) View(android.view.View) Toolbar(android.support.v7.widget.Toolbar)

Example 19 with RefreshLayout

use of com.scwang.smartrefresh.layout.api.RefreshLayout 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 20 with RefreshLayout

use of com.scwang.smartrefresh.layout.api.RefreshLayout 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

RefreshLayout (com.scwang.smartrefresh.layout.api.RefreshLayout)40 View (android.view.View)26 Toolbar (android.support.v7.widget.Toolbar)24 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)22 OnRefreshListener (com.scwang.smartrefresh.layout.listener.OnRefreshListener)20 SmartRefreshLayout (com.scwang.smartrefresh.layout.SmartRefreshLayout)17 RecyclerView (android.support.v7.widget.RecyclerView)15 OnLoadmoreListener (com.scwang.smartrefresh.layout.listener.OnLoadmoreListener)12 SmartViewHolder (com.scwang.refreshlayout.adapter.SmartViewHolder)11 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)10 DividerItemDecoration (android.support.v7.widget.DividerItemDecoration)10 AdapterView (android.widget.AdapterView)10 SimpleMultiPurposeListener (com.scwang.smartrefresh.layout.listener.SimpleMultiPurposeListener)9 BaseRecyclerAdapter (com.scwang.refreshlayout.adapter.BaseRecyclerAdapter)7 RefreshHeader (com.scwang.smartrefresh.layout.api.RefreshHeader)7 TextView (android.widget.TextView)6 ImageView (android.widget.ImageView)5 RefreshState (com.scwang.smartrefresh.layout.constant.RefreshState)5 ClassicsHeader (com.scwang.smartrefresh.layout.header.ClassicsHeader)5 OnLoadMoreListener (com.scwang.smartrefresh.layout.listener.OnLoadMoreListener)5