首页 > 其他分享 >LoadMoreListView+SwipeRefreshLayout(分页下拉)基本结构

LoadMoreListView+SwipeRefreshLayout(分页下拉)基本结构

时间:2023-04-06 22:08:03浏览次数:48  
标签:LoadMoreListView 分页 void SwipeRefreshLayout item new import public View


一切为了快速迭代

import java.util.ArrayList;

import org.json.JSONObject;

import android.animation.ObjectAnimator;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.android.volley.Response.Listener;
import com.widget.view.LoadMoreListView.OnLoadMoreListener;
import com.yirui.youbao.CommonAdapter;
import com.yirui.youbao.ViewHolder;
import com.yirui.youbao.ViewWrapper;
import com.yirui.youbao.app.R;
import com.yirui.youbao.model.Pagination;
import com.yirui.youbao.model.Parking;
import com.yirui.youbao.net.Commands;
import com.yirui.youbao.net.VolleyHelper;
import com.yirui.youbao.util.Json;

/**
 * 
 * 
 * @author pythoner
 * 
 */
public class ParkingPayedListFragment extends BaseFragment {

	private com.widget.view.LoadMoreListView listView;
	private CommonAdapter<Parking> adapter;
	private Pagination pagination = new Pagination();
	private ArrayList<Parking> parkings = new ArrayList<Parking>();

	private SwipeRefreshLayout swipeRefreshLayout;

	public static ParkingPayedListFragment newInstance(/*KeyValue kv*/) {
		ParkingPayedListFragment fragment = new ParkingPayedListFragment();
		Bundle bundle = new Bundle();
		// bundle.putParcelable("KeyValue", kv);
		fragment.setArguments(bundle);
		return fragment;
	}

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Bundle args = getArguments();
		if (args != null) {
			// curKeyValue = args.getParcelable("KeyValue");
		}
	}

	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);
		View view = inflater.inflate(R.layout.fragment_list_comm, container,false);
		listView = (com.widget.view.LoadMoreListView) view.findViewById(R.id.listView);
		listView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				//
			}
		});
		listView.setOnLoadMoreListener(new onl oadMoreListener() {

			@Override
			public void onl oadMore() {
				pagination.page++;
				doDefaultParkingQuery();
			}
		});

		swipeRefreshLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipeRefreshLayout);
		swipeRefreshLayout.setColorScheme(R.color.scheme_green,R.color.scheme_yellow, R.color.scheme_gray, R.color.scheme_red);
		swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {

					@Override
					public void onRefresh() {
						// TODO Auto-generated method stub
						refreshListView();
						//
						doDefaultParkingQuery();
					}
				});

		doDefaultParkingQuery();

		return view;
	}

	private void doDefaultParkingQuery() {
		doCommandParkingQuery("潍坊路", pagination);
	}

	private void doCommandParkingQuery(String keyword, Pagination pagination) {
		Commands.doCommandParkingQuery(context, keyword, pagination,
				new Listener<JSONObject>() {
					@Override
					public void onResponse(JSONObject response) {
						// TODO Auto-generated method stub
						// Log.i("tag", response.toString());
						if (context.isSuccess(response)) {
							updateViews(Json.parseParkings(response));
						}
					}

				});
	}
	
	private void refreshListView() {
		listView.resetLoadMoreListener();
		pagination.page = 1;
		parkings.clear();
		// notifyDataSetChanged();
	}
	
	private void closeRefreshing() {
		if (swipeRefreshLayout != null && swipeRefreshLayout.isRefreshing()) {
			swipeRefreshLayout.setRefreshing(false);
		}
	}

	private void updateViews(Object obj) {
		closeRefreshing();
		if (obj == null) {
			return;
		}
		ArrayList<Parking> list = (ArrayList<Parking>) obj;
		// Log.i("tag", "list.size==="+list.size());
		listView.onLoadMoreComplete();
		if (list.size() == 0) {
			listView.removeLoadMoreListener();
			return;
		}
		parkings.addAll(list);
		notifyDataSetChanged();

	}

	private void notifyDataSetChanged() {
		if (adapter == null) {
			listView.setAdapter(adapter = new CommonAdapter<Parking>(context,
					parkings, R.layout.item_for_parkings) {
				@Override
				public void setValues(ViewHolder helper, Parking item,
						int position) {
					createItem(helper, item, position);
				}
			});
		} else {
			adapter.notifyDataSetChanged();
		}
	}

	//打开关闭下滑面板用,本例并不关心,可忽略
	private View lastContainer = null;
	private Parking lastItem = null;
	private void createItem(ViewHolder helper, final Parking item,
			final int position) {
		ImageView item_0 = helper.getView(R.id.item_0);
		VolleyHelper.loadImageByVolley(item.getImage(), item_0,
				R.drawable.default_face);
		helper.setText(R.id.item_1, item.getName());
		helper.setText(R.id.item_2, item.getPrice());
		// helper.setText(R.id.item_3, item.getName());
		final View container = helper.getView(R.id.container);
		final int maxHeight = 140;// 菜单的高
		if (item.isOpen()) {
			container.setLayoutParams(new LinearLayout.LayoutParams(
					LinearLayout.LayoutParams.MATCH_PARENT, maxHeight));
		} else {
			container.setLayoutParams(new LinearLayout.LayoutParams(
					LinearLayout.LayoutParams.MATCH_PARENT, 0));
		}
		helper.getView(R.id.item_4).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						if (container == lastContainer) {
							doSliding(container, maxHeight);
							item.setOpen(!item.isOpen());
						} else {
							doSliding(container, maxHeight);
							item.setOpen(true);
							if (lastContainer != null) {
								doSliding(lastContainer, 0);
								lastItem.setOpen(false);
							}
							lastContainer = container;
							lastItem = item;
						}

					}
				});

		helper.getView(R.id.btn_0).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Log.i("tag", "btn_0[" + position + "]");
					}
				});
		helper.getView(R.id.btn_1).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Log.i("tag", "btn_1[" + position + "]");
					}
				});
		helper.getView(R.id.btn_2).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Log.i("tag", "btn_2[" + position + "]");
					}
				});

		helper.getView(R.id.btn_3).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Log.i("tag", "btn_3[" + position + "]");
					}
				});
		helper.getView(R.id.btn_4).setOnClickListener(
				new View.OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Log.i("tag", "btn_4[" + position + "]");
					}
				});
	}

	private void doSliding(View view, int maxHeight) {
		ViewWrapper wrapper = new ViewWrapper(view);
		if (view.getHeight() == 0) {
			ObjectAnimator.ofInt(wrapper, "height", maxHeight).setDuration(400)
					.start();
		} else {
			ObjectAnimator.ofInt(wrapper, "height", 0).setDuration(400).start();
		}
	}

	@Override
	public void onResume() {
		super.onResume();
	}

	@Override
	public void onPause() {
		super.onPause();
	}

	@Override
	public void onDestroy() {
		super.onDestroy();
	}

	@Override
	public void onDestroyView() {
		// TODO Auto-generated method stub
		super.onDestroyView();
	}

}




布局


<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/swipeRefreshLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <com.widget.view.LoadMoreListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:footerDividersEnabled="false"
        android:headerDividersEnabled="false"
        android:cacheColorHint="@android:color/transparent" />

</android.support.v4.widget.SwipeRefreshLayout>




/*
 * 分页
 */
public class Pagination {

	public int page=1;
	public int size=10;
	
	public void reset(){
		page=1;
		size=10;
	}
	
	public int nextPage(){
		return page++;
	}
}






https://github.com/android-cjj/Android-MaterialRefreshLayout


标签:LoadMoreListView,分页,void,SwipeRefreshLayout,item,new,import,public,View
From: https://blog.51cto.com/u_5454003/6174211

相关文章

  • myBatis-分页
    1.前言MyBatis,作为目前流行的ORM框架,大大方便了日常开发。而对于分页查询,虽然可以通过SQL的limit语句实现,但是比较繁琐。1.1.Limit方式以前的分页查询,拼接sql语句:BookMapper.java接口://根据limit语句拼接,进行相应的分页List<Book>selectBySQL(@Param("start")intst......
  • vue 手写分页
       data:{        crossing_status:CROSSING_STATUS,        crossing_list:[],        time:null,        log:{          page:1,          pages:......
  • mysql 两百万数据 深分页性能优化
    --ddlCREATETABLE`student`( `id`int(11)NOTNULLAUTO_INCREMENTCOMMENT'主键', `user_no`varchar(50)DEFAULT''COMMENT'学号', `user_name`varchar(50)DEFAULT''COMMENT'姓名', `score`decimal(10,2)DEFAU......
  • 使用PHP将长文章分页
    当文章内容特长时,为了方便阅读和页面展示我们一般将内容分页来显示。而一般分页处理是在后台发布文章的时候就将提交的内容生成多个分页后的静态文件。本文我们结合实例来讲解采用PHP动态将长文章内容进行分页处理。如何分页手动分页:一般在编辑内容时加入特殊分页标记,如{pages},提交......
  • 分页查询
    DQL-分页查询select字段列表from表名limit起始索引,查询记录数;注意:起始索引从0开始,起始索引=(查询页码-1)*每页显示记录数分页查询是数据库的方言,不同的数据库有不同的实现,mysql中是limit如果查询的是第一页的数据,起始索引可以省略,直接简写为limit10 代码:select......
  • 亿万级分库分表后如何进行跨表分页查询
    亿万级分库分表后如何进行跨表分页查询 目录全局表查询禁止跳页查询按日期的二次查询法大数据集成法NewSql法有序的二次查询法测试分页结果并行查询和排序 前言在常规的应用系统开发中,很少会涉及到需要对数据进行分库或者分表的操作,多数情况下,我们习惯使用OR......
  • MySQL带排序的分页查询优化
    MySQL带排序的分页查询优化需求在日常开发中,经常会遇到这么一种情况,一张表的数据量较大(500万左右)的时候,对其进行分页查询的时候,在分页比较深的情况下,查询效率会急剧下降。对于这种情况,我们需要做一些分页查询的优化。准备创建脚本CREATETABLEstudent(idINTNOTNULL......
  • bootstrap之carousel轮播图自定义分页器
    最近要开发一个轮播图的看板页面,试用下bootstrap的轮播图组件,因为分页器的部分需要自定义(文字过长需要放到轮播图区域的外面),使用 Listgroup组件作为轮播图的分页器放在左边。 <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"/><metahttp-equiv=......
  • 【微信小程序-原生开发】实用教程14 - 列表的分页加载,触底加载更多(含无更多数据的提醒
    此页可在动态列表的基础上完善,也可以单独学习【微信小程序-原生开发】实用教程10-动态列表的新增、修改、删除效果预览核心技术列表的分页加载skip跳跃到指定下标开始查询limit限制返回的数据数量(云数据库最多20条/次,云函数最多100条/次)skip配合limit使用,便能实现分页啦!.ski......
  • Mybatis之数据库连接+PageHelper分页插件+Mybatis-Plus插件
    MyBatisPlus教程(人人便成为)https://www.cnblogs.com/chch213/p/16320820.html前言ORM框架:对象关系映射 objectrelationalmapping 半自动ORM映射工具(自己编写sql语句)  Hibernater属于全自动映射规则:数据库表>类|表字段>类的属性|表数据>对象 JDBC操......