Simple use of android-swiperefreshlayout drop-down control

Let’s take a look at swiperefreshlayout today, which is officially launched by android.
Before using, add some dependencies. At present, my Androidstudio can’t directly search for the dependency, we go directly to the official search
Insert picture description here

dependencies {
    
    
    implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
}

You can use it after adding the dependency. After I added the xml file is available, but the main Java file cannot be found, so I need to rebuild (build), first clean the project, then rebuild the project. After the
Insert picture description here
basic dependencies are added , let ’s see how to use it.

1. The xml file, use this tag to wrap the content in.
Insert picture description here
2. In the java file
(1), get the control id of swimefresh
(2), set up her monitoring event
(3), this is the data in her monitoring event Refresh
(4), set the setrefreshing method for her, false means stop loading after the data is processed, otherwise it will keep going in circles
PS: setColorSchemeResources can set the color of the circle, and you can give multiple
colors.


Insert picture description here
Above : ps: To show the effect, I gave him a few seconds. Can not

Above code:

       swipeRefreshLayout = findViewById(R.id.demo_swiperefresh);
        TextView textView = findViewById(R.id.demo_tv);
//        设置圈圈的颜色
        swipeRefreshLayout.setColorSchemeResources(R.color.yellow,R.color.black,R.color.teal_200);
        swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    
    
            @Override
            public void onRefresh() {
    
    
                new Handler().postDelayed(new Runnable() {
    
    
                    @Override
                    public void run() {
    
    
                        textView.setText("我是刷新后的数据");
//                        处理完数据后停止加载
                        swipeRefreshLayout.setRefreshing(false);
                    }
                }, 2000);
            }
        });

The demo effect picture:
Insert picture description here

Guess you like

Origin blog.csdn.net/Willow_Spring/article/details/112758046