GridView刷新

转载 2016年06月02日 08:13:00

PulltorefreshLibary为依赖包

layout 中的 activity_main

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <com.handmark.pulltorefresh.library.PullToRefreshGridView
        xmlns:ptr="http://schemas.android.com/apk/res-auto"
        android:id="@+id/pull_refresh_grid"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:numColumns="3"
        ptr:ptrMode="both" />

</LinearLayout>



ExpandGridView

/**
 * Copyright (C) 2013-2014 EaseMobTechnologies. All rights reserved.
 *
 * Licensed under the Apache License,Version 2.0 (the "License");
 * you may not use this file except incompliance with the License.
 * You may obtain a copy of the Licenseat
 *    http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law oragreed to in writing, software
 * distributed under the License isdistributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OFANY KIND, either express or implied.
 * See the License for the specificlanguage governing permissions and
 * limitations under the License.
 */
package com.example.mygridview;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.GridView;

public class ExpandGridView extends GridView {

    public ExpandGridView(Context context){
        super(context);
    }
   
    public ExpandGridView(Context context,AttributeSet attrs) {
        super(context, attrs);
    }


    /*
    * 测量宽度和高
    * */
    @Override
    public void onMeasure(intwidthMeasureSpec, int heightMeasureSpec) {
        //实际高度
        int expandSpec =MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2,MeasureSpec.AT_MOST);
        super.onMeasure(widthMeasureSpec,expandSpec);
    }


}
 

MainActivity

packagecom.example.mygridview;

 

importjava.util.ArrayList;

 

importandroid.app.Activity;

importandroid.os.Bundle;

importandroid.widget.GridView;

 

importcom.handmark.pulltorefresh.library.PullToRefreshBase;

importcom.handmark.pulltorefresh.library.PullToRefreshBase.OnRefreshListener2;

importcom.handmark.pulltorefresh.library.PullToRefreshGridView;

importcom.handmark.pulltorefresh.library.PullToRefreshScrollView;

publicclass MainActivity extends Activity {

 

    private PullToRefreshGridViewmPullRefreshGridView ;

    private PullToRefreshScrollViewscro_luck_PullToRefreshScrollView;

    private MyGridViewAdapter myGridViewAdapter;

    ArrayList<Integer> imgIdList=newArrayList<Integer>();

    ArrayList<Integer> allImgIdList=newArrayList<Integer>();

    private GridView gridView;

     private int currPage;

    @Override

    protected void onCreate(BundlesavedInstanceState) {

       super.onCreate(savedInstanceState);

       setContentView(R.layout.activity_main);

   

       mPullRefreshGridView  = (PullToRefreshGridView)findViewById(R.id.pull_refresh_grid);

       gridView =mPullRefreshGridView.getRefreshableView();

    myGridViewAdapter = newMyGridViewAdapter(this);

    mPullRefreshGridView.setAdapter(myGridViewAdapter);

    getData();

    myGridViewAdapter.addrest(imgIdList);

   

   

     //ʵÏÖÉÏÀ­Ë¢ÐÂÓëÏÂÀ­¼ÓÔØ

   mPullRefreshGridView.setOnRefreshListener(new OnRefreshListener2() {

 

        @SuppressWarnings("rawtypes")

        @Override

        public voidonPullDownToRefresh(PullToRefreshBase refreshView) {

 

            imgIdList.clear();

            getData();

           myGridViewAdapter.addrest(imgIdList);

           

            refreshView.onRefreshComplete();

        }

 

        @SuppressWarnings("rawtypes")

        @Override

        public void onPullUpToRefresh(PullToRefreshBaserefreshView) {

       

           

            allImgIdList.addAll(imgIdList);

        myGridViewAdapter.addrest(allImgIdList);

           refreshView.onRefreshComplete();

        }

 

    });

 

    }

 

    private void getData() {

for(int i = 0; i < 50; i++) {

    imgIdList.add(R.drawable.ic_launcher);

}     

    }

}




MyGridViewAdapter

package com.example.mygridview;

 

import java.util.ArrayList;

 

import android.content.Context;

import android.view.View;

import android.view.ViewGroup;

import android.widget.BaseAdapter;

import android.widget.ImageView;

 

public class MyGridViewAdapter extends BaseAdapter {

 

    Contextcontext;

   

    ArrayList<Integer>imgIdList=new ArrayList<Integer>();

    publicMyGridViewAdapter(Context context) {

        super();

        this.context= context;

    }

    public voidaddrest(ArrayList<Integer> imgIdList){

        this.imgIdList.clear();

        this.imgIdList.addAll(imgIdList);

        this.notifyDataSetChanged();

    }

 

    @Override

    public intgetCount() {

       

        returnimgIdList.size();

    }

 

    @Override

    public ObjectgetItem(int position) {

        // TODOAuto-generated method stub

        returnnull;

    }

 

    @Override

    public longgetItemId(int position) {

        // TODOAuto-generated method stub

        return 0;

    }

 

   

   

    @Override

    public ViewgetView(int position, View convertView, ViewGroup parent) {

        ImageViewimageView=new ImageView(context);

        imageView.setImageResource(R.drawable.ic_launcher);

       

        returnimageView;

    }

 

 

}



相关文章推荐

GridView分组带下拉刷新

  • 2015-08-19 09:43
  • 1.36MB
  • 下载

Android自定义控件(一) 下拉刷新,上拉分页加载更多(支持ListView, GridView, ScrollView)

项目中用到了下拉刷新和上啦加载

支持listview、GridView、普通布局、scrollview和viewpager的下拉刷新控件

支持listview、GridView、scrollview和viewpager的下拉刷新(经测试未发现bug),但是不支持viewpager中嵌套listview、GridView等可上下滑动组件的...

Android PullToRefresh (ListView GridView 下拉刷新) 使用详解

出处:http://blog.csdn.net/lmj623565791/article/details/38238749,本文出自:【张鸿洋的博客】 群里一哥们今天聊天偶然提到这个git hub上...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)