
package com.test;
import android.app.ListActivity;
import android.os.Bundle;
import android.os.Handler;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.LinearLayout.LayoutParams;
public class test extends ListActivity implements OnScrollListener {
? ? ? ? Aleph0 adapter = new Aleph0();
? ? ? ? int lastItem = 0;
? ? ? ? int mProgressStatus = 0;
? ? ? ? private Handler mHandler = new Handler();
? ? ? ? ProgressBar progressBar;
? ? ? ? protected void onCreate(Bundle savedInstanceState) {
? ? ? ? ? ? ? ? super.onCreate(savedInstanceState);
? ? ? ? ? ? ? ? LinearLayout searchLayout = new LinearLayout(this);
? ? ? ? ? ? ? ? searchLayout.setOrientation(LinearLayout.HORIZONTAL);
? ? ? ? ? ? ? ? progressBar = new ProgressBar(this);
? ? ? ? ? ? ? ? progressBar.setPadding(0, 0, 15, 0);
? ? ? ? ? ? ? ? searchLayout.addView(progressBar, new LinearLayout.LayoutParams(
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? LinearLayout.LayoutParams.WRAP_CONTENT,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? LinearLayout.LayoutParams.WRAP_CONTENT));
? ? ? ? ? ? ? ? TextView textView = new TextView(this);
? ? ? ? ? ? ? ? textView.setText("加载中...");
? ? ? ? ? ? ? ? textView.setGravity(Gravity.CENTER_VERTICAL);
? ? ? ? ? ? ? ? searchLayout.addView(textView, new LinearLayout.LayoutParams(
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? LinearLayout.LayoutParams.FILL_PARENT,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? LinearLayout.LayoutParams.FILL_PARENT));
? ? ? ? ? ? ? ? searchLayout.setGravity(Gravity.CENTER);
? ? ? ? ? ? ? ? LinearLayout loadingLayout = new LinearLayout(this);
? ? ? ? ? ? ? ? loadingLayout.addView(searchLayout, new LinearLayout.LayoutParams(
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? LinearLayout.LayoutParams.WRAP_CONTENT,
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? LinearLayout.LayoutParams.WRAP_CONTENT));
? ? ? ? ? ? ? ? loadingLayout.setGravity(Gravity.CENTER);
? ? ? ? ? ? ? ? getListView().addFooterView(loadingLayout);
? ? ? ? ? ? ? ? // Start lengthy operation in a background thread
? ? ? ? ? ? ? ? // new Thread(new Runnable() {
? ? ? ? ? ? ? ? // public void run() {
? ? ? ? ? ? ? ? // while (mProgressStatus < 100) {
? ? ? ? ? ? ? ? //
? ? ? ? ? ? ? ? // // Update the progress bar
? ? ? ? ? ? ? ? // mHandler.post(new Runnable() {
? ? ? ? ? ? ? ? // public void run() {
? ? ? ? ? ? ? ? // progressBar.setProgress(mProgressStatus);
? ? ? ? ? ? ? ? // }
? ? ? ? ? ? ? ? // });
? ? ? ? ? ? ? ? // }
? ? ? ? ? ? ? ? // }
? ? ? ? ? ? ? ? // }).start();
? ? ? ? ? ? ? ? registerForContextMenu(getListView());
? ? ? ? ? ? ? ? setListAdapter(adapter);
? ? ? ? ? ? ? ? getListView().setOnScrollListener(this);
? ? ? ? }
? ? ? ? public void onScroll(AbsListView v, int firstVisibleItem,
? ? ? ? ? ? ? ? ? ? ? ? int visibleItemCount, int totalItemCount) {
? ? ? ? ? ? ? ? //lastItem = firstVisibleItem + visibleItemCount - 1;
? ? ? ? ? ? ? ? //System.out.println("lastItem:" + lastItem);
? ? ? ? }
? ? ? ? public void onScrollStateChanged(AbsListView v, int state) {
//? ? ? ? ? ? ? ? if (lastItem == adapter.count
//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? && state == OnScrollListener.SCROLL_STATE_IDLE) {
//? ? ? ? ? ? ? ? ? ? ? ? adapter.count += 10;
//? ? ? ? ? ? ? ? ? ? ? ? adapter.notifyDataSetChanged();
//? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? if (state == OnScrollListener.SCROLL_STATE_IDLE) {
? ? ? ? ? ? ? ? ? ? ? ? adapter.count += 10;
? ? ? ? ? ? ? ? ? ? ? ? adapter.notifyDataSetChanged();
? ? ? ? ? ? ? ? }
? ? ? ? }
? ? ? ? class Aleph0 extends BaseAdapter {
? ? ? ? ? ? ? ? int count = 10;
? ? ? ? ? ? ? ? public int getCount() {
? ? ? ? ? ? ? ? ? ? ? ? return count;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? public Object getItem(int pos) {
? ? ? ? ? ? ? ? ? ? ? ? return pos;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? public long getItemId(int pos) {
? ? ? ? ? ? ? ? ? ? ? ? return pos;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? public View getView(int pos, View v, ViewGroup p) {
? ? ? ? ? ? ? ? ? ? ? ? TextView view = new TextView(test.this);
? ? ? ? ? ? ? ? ? ? ? ? view.setText("entry " + pos);
? ? ? ? ? ? ? ? ? ? ? ? view.setHeight(90);
? ? ? ? ? ? ? ? ? ? ? ? return view;
? ? ? ? ? ? ? ? }
? ? ? ? }
}
详细解决方案
Android listview如何实现滚动分页
热度:63 发布时间:2016-05-01 17:23:16.0
相关解决方案
- android 读取byte[]中的元素解决方案
- android 标题栏兑现方式
- android 中Activity向BroadcastReceiver发送数据,该怎么解决
- Android 4.0 为什么模拟器老是提示小弟我谷歌拼音输入法已停止
- android:getSharedPreferences() 这是哪个类的方法解决思路
- android 怎么判断一个程序是否联网
- android RadioButton如何设置默认选中
- ListView 中加入 EditText后的焦点有关问题
- android 怎么重新设置锚点
- android 图片对象获取的有关问题
- android 关于服务连接的疑义
- android 怎么实现对view的放大和缩小
- android ID,该如何处理
- 准备复习2-3个月,看java+android,请问有经验者,怎么看效果最好》
- android UI线程与AsyncTask的有关问题
- android(java) 中文乱码的有关问题
- asp.net ListView 控件导出EXCEL档 出现一点有关问题身份证号后3位全部变成0,怎么解决哦
- C# ListView Item 焦点获取 有关问题 (winform) 控件高手别走。
- ListView,该怎么解决
- 必须在 ListView“ListView2”下指定项占位符
- ListView 控件怎么增加 编辑,删除,更新按钮
- listview 与 repeater 实施效率是不是一样高
- ListView+DataPager 分页性能怎么
- ASP listview 动态更改selectCommand,该怎么处理
- asp.net3.5 listview 如何样鼠标放在行上整行高亮显示 选择
- ListView+DataPager如何实现只取当前页记录并实现分页
- ListView 绑定ImageList 的 有关问题.
- android 动态设立控件高度
- Android test project 编译方法
- android 4.03启动出错,显示"Encryption Unsuccessful"该如何解决