android滑动分页
2011-05-05 15:00
155 查看
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之Tab分页标签的实现方法一-----可滑动的Tab的3种方式
- Android腾讯微博客户端开发5:利用FootView实现ListView滑动动态加载实现分页
- android左右滑动加载分页以及动态加载数据
- android 滑动分页
- android listview左右滑动分页(viewpager嵌套listview进行分页),焦点图带圆焦点
- Android实现基于滑动的SQLite数据分页加载技术(附demo源码下载)
- Android中使用GridView分页显示系统所安装的应用,支持拖动与手势滑动
- Android 开源框架ViewPageIndicator或ActionBarSherlock实现tab滑动分页效果
- android 滑动分页
- Android中分页滑动实现总结
- Android程序开发之Listview下拉刷新上拉(滑动分页)加载更多
- android左右滑动加载分页以及动态加载数据
- ANDROID GridView 分页平滑滑动 效果的实现(基于android TV遥控器操作)
- Android腾讯微博客户端开发五:利用FootView实现ListView滑动动态加载实现分页
- Android中使用GridView分页显示系统所安装的应用,支持拖动与手势滑动
- Android App中使用ViewPager实现滑动分页的要点解析
- Android中使用GridView分页显示系统所安装的应用,支持拖动与手势滑动
- Android SQLite PhoneGap sencha touch 中调用Java原生程序,数据加载到页面,并实现滑动分页
- android左右滑动加载分页以及动态加载数据
- android viewpager+fragment与利用viewpager滑动分页小技巧