GridView和各种相关控件的上拉和下拉

Posted glj521

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了GridView和各种相关控件的上拉和下拉相关的知识,希望对你有一定的参考价值。

下载依赖类库

https://yunpan.cn/cBs8jPPYRQnTV  访问密码 f721

把类库的东西全部复制到工程

在app的bui下添加

dependencies {


compile ‘com.android.support:recyclerview-v7:23.+‘
compile ‘com.android.support:cardview-v7:23.+‘
}
改成相应的v7包的版本号如:7.23


布局中:使用
com.jingchen.pulltorefresh.PullToRefreshLayout作为主布局
<?xml version="1.0" encoding="utf-8"?>
<com.jingchen.pulltorefresh.PullToRefreshLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/pulllayout"

    tools:context="tests.bwie.com.mygridview.MainActivity">

    <com.jingchen.pulltorefresh.PullableGridView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:numColumns="3"
        android:id="@+id/gv" />
</com.jingchen.pulltorefresh.PullToRefreshLayout>

 

调用时

package tests.bwie.com.mygridview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jingchen.pulltorefresh.PullToRefreshLayout;
import com.jingchen.pulltorefresh.PullableGridView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private PullableGridView gv;
    private PullToRefreshLayout pulllayout;
    List<String> list = new ArrayList<>();
    private MyAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        pulllayout = (PullToRefreshLayout) findViewById(R.id.pulllayout);
        gv = (PullableGridView) findViewById(R.id.gv);

//        pulllayout.setCustomRefreshView(View);自定义下拉头
//        pulllayout.setCustomLoadmoreView(View v);自定义上拉头

        //设置可以下拉
        pulllayout.setPullDownEnable(true);
        //设置可以上拉
        pulllayout.setPullUpEnable(false);


        for(int i = 0;i<10;i++){
            list.add("视频"+i);
        }

        adapter = new MyAdapter();
        gv.setAdapter(adapter);


        pulllayout.setOnPullListener(new PullToRefreshLayout.OnPullListener() {
            @Override
            public void onRefresh(PullToRefreshLayout pullToRefreshLayout) {

                pulllayout.refreshFinish(PullToRefreshLayout.SUCCEED);
                list.add("hhhh");
                adapter.notifyDataSetChanged();

            }

            @Override
            public void onLoadMore(PullToRefreshLayout pullToRefreshLayout) {

                pulllayout.loadmoreFinish(PullToRefreshLayout.SUCCEED);
                list.add("dddd");
                adapter.notifyDataSetChanged();

            }
        });


        //设置下拉刷新过程监听器
//        pulllayout.setOnRefreshProcessListener(new PullToRefreshLayout.OnPullProcessListener() {
//            @Override
//            public void onPrepare(View v, int which) {
//
//            }
//
//            @Override
//            public void onStart(View v, int which) {
//
//            }
//
//            @Override
//            public void onHandling(View v, int which) {
//
//            }
//
//            @Override
//            public void onFinish(View v, int which) {
//
//            }
//
//            @Override
//            public void onPull(View v, float pullDistance, int which) {
//
//            }
//        });



    }


    class MyAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return list.size();
        }

        @Override
        public Object getItem(int position) {
            return null;
        }

        @Override
        public long getItemId(int position) {
            return 0;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            if(convertView==null){
                convertView=View.inflate(MainActivity.this,android.R.layout.simple_list_item_1,null);
            }
            TextView tv = (TextView) convertView.findViewById(android.R.id.text1);
            tv.setText(list.get(position));
            return convertView;
        }
    }
}

 



以上是关于GridView和各种相关控件的上拉和下拉的主要内容,如果未能解决你的问题,请参考以下文章

「小程序JAVA实战」小程序页面的上拉下拉刷新(50)

上拉和下拉的解释

上拉和下拉的解释

iOS常用刷新控件(下拉、上拉)详解

单片机中输入上拉,输入下拉,内部上拉,下拉是啥意思

html5+css3实现上拉和下拉刷新