Search in sources :

Example 1 with SmartRefreshLayout

use of com.scwang.smartrefresh.layout.SmartRefreshLayout 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 2 with SmartRefreshLayout

use of com.scwang.smartrefresh.layout.SmartRefreshLayout in project AgentWeb by Justson.

the class SmartRefreshWebFragment method onViewCreated.

@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final SmartRefreshLayout mSmartRefreshLayout = (SmartRefreshLayout) this.mSmartRefreshWebLayout.getLayout();
    final WebView mWebView = this.mSmartRefreshWebLayout.getWebView();
    mSmartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {

        @Override
        public void onRefresh(RefreshLayout refreshlayout) {
            mAgentWeb.getUrlLoader().reload();
            mSmartRefreshLayout.postDelayed(new Runnable() {

                @Override
                public void run() {
                    mSmartRefreshLayout.finishRefresh();
                }
            }, 2000);
        }
    });
    mSmartRefreshLayout.autoRefresh();
}
Also used : SmartRefreshLayout(com.scwang.smartrefresh.layout.SmartRefreshLayout) RefreshLayout(com.scwang.smartrefresh.layout.api.RefreshLayout) SmartRefreshLayout(com.scwang.smartrefresh.layout.SmartRefreshLayout) WebView(android.webkit.WebView) OnRefreshListener(com.scwang.smartrefresh.layout.listener.OnRefreshListener)

Aggregations

SmartRefreshLayout (com.scwang.smartrefresh.layout.SmartRefreshLayout)2 RefreshLayout (com.scwang.smartrefresh.layout.api.RefreshLayout)2 OnRefreshListener (com.scwang.smartrefresh.layout.listener.OnRefreshListener)2 BottomSheetDialog (android.support.design.widget.BottomSheetDialog)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 WebView (android.webkit.WebView)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 BaseRecyclerAdapter (com.scwang.refreshlayout.adapter.BaseRecyclerAdapter)1 SmartViewHolder (com.scwang.refreshlayout.adapter.SmartViewHolder)1 OnLoadMoreListener (com.scwang.smartrefresh.layout.listener.OnLoadMoreListener)1