private void initData() { tableBodyAdapter = new CommonAdapter<T>(context, viewCreator, new ArrayList<T>()); lv_page_body.setAdapter(tableBodyAdapter); // add lv_page_body.setOnPositionChangedListener((OnPositionChangedListener) context); // new }
private void initData(ArrayList<T> arraylist) { tableBodyAdapter = new CommonAdapter<T>(context, viewCreator, arraylist); lv_page_body.setAdapter(tableBodyAdapter); // add lv_page_body.setOnPositionChangedListener((OnPositionChangedListener) context); // new if (arraylist.size() < 5) { lv_page_body.setTag(UIHelper.LISTVIEW_DATA_FULL); lvNews_foot_more.setText(R.string.load_full); // 已加载全部 lvNews_foot_progress.setVisibility(ProgressBar.GONE); } }
private void bindEvents() { lv_page_body.setOnItemClickListener(new OnItemClickListener()); // lv_page_body.setOnItemLongClickListener(new OnItemLongClick()); // 列表加载更多的操作 lv_page_body.setOnScrollListener( new AbsListView.OnScrollListener() { public void onScrollStateChanged(AbsListView view, int scrollState) { lv_page_body.onScrollStateChanged(view, scrollState); // 数据为空--不用继续下面代码了 if (tableBodyAdapter.getDataCache().size() == 0) return; // 判断是否滚动到底部 boolean scrollEnd = false; try { if (view.getPositionForView(footView) == view.getLastVisiblePosition()) scrollEnd = true; } catch (Exception e) { scrollEnd = false; } int lvDataState = StringUtils.toInt(lv_page_body.getTag()); if (scrollEnd && lvDataState == UIHelper.LISTVIEW_DATA_MORE) { lv_page_body.setTag(UIHelper.LISTVIEW_DATA_LOADING); lvNews_foot_more.setText(R.string.load_ing); // 设置 显示“加载中。。。” lvNews_foot_progress.setVisibility(View.VISIBLE); action = UIHelper.LISTVIEW_ACTION_SCROLL; requestAction.pageBean.setCurrentPage(requestAction.pageBean.getCurrentPage() + 1); loadPaginationData(); } } public void onScroll( AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { lv_page_body.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount); } }); // 刷新的操作 lv_page_body.setOnRefreshListener( new PullToRefreshListView.OnRefreshListener() { public void onRefresh() { action = UIHelper.LISTVIEW_ACTION_REFRESH; lvNews_foot_more.setText(null); lvNews_foot_progress.setVisibility(ProgressBar.GONE); requestAction.pageBean.setCurrentPage(1); loadPaginationData(); } }); }
private void setUpViews() { lv_page_body = (PullToRefreshListView) paginationView.findViewById(R.id.lv_pagination_widget_data_body); lvNews_foot_more = (TextView) footView.findViewById(R.id.listview_foot_more); lvNews_foot_progress = (ProgressBar) footView.findViewById(R.id.listview_foot_progress); lv_page_body.addFooterView(footView); }
@SuppressWarnings({"unchecked", "deprecation"}) public void success(Object object) { PagerResponse response = (PagerResponse) object; if (null == requestAction.pageBean) { return; } int allCount = response.pageBean.getAllCount(); if (allCount == 0) {} requestAction.pageBean.setAllCount(allCount); int count = 0; /** 没有记录或记录为空的时候 */ if (response.pageBean.getPageDatas() != null) { count = ((List<T>) response.pageBean.getPageDatas()).size(); } if (action == UIHelper.LISTVIEW_ACTION_REFRESH) { tableBodyAdapter.removeAll(); } if (count == 0 || allCount == 0) { Toast tost = Toast.makeText(context, "没有更多记录!", Toast.LENGTH_LONG); tost.setGravity(Gravity.CENTER, 0, 0); tost.show(); lv_page_body.setTag(UIHelper.LISTVIEW_DATA_EMPTY); lvNews_foot_more.setText(R.string.load_empty); } if (count < RequestParamConfig.pagesize && count > -1) { // 末页返还 lv_page_body.setTag(UIHelper.LISTVIEW_DATA_FULL); tableBodyAdapter.add((List<T>) response.pageBean.getPageDatas()); tableBodyAdapter.notifyDataSetChanged(); lvNews_foot_more.setText(R.string.load_full); // 已加载全部 } else if (count == RequestParamConfig.pagesize) { lv_page_body.setTag(UIHelper.LISTVIEW_DATA_MORE); tableBodyAdapter.add((List<T>) response.pageBean.getPageDatas()); tableBodyAdapter.notifyDataSetChanged(); lvNews_foot_more.setText(R.string.load_more); } lvNews_foot_progress.setVisibility(ProgressBar.GONE); if (action == UIHelper.LISTVIEW_ACTION_REFRESH) { lv_page_body.onRefreshComplete("最近更新:" + new Date().toLocaleString()); lv_page_body.setSelection(0); } else if (action == UIHelper.LISTVIEW_ACTION_CHANGE_CATALOG) { lv_page_body.onRefreshComplete(); lv_page_body.setSelection(0); } }