- 浏览: 325632 次
- 性别:
- 来自: 上海
文章分类
最新评论
-
xuanyuanxiaoxue:
...
Android - LayoutInflater -
柴兴博:
不错 多谢
Android 悬浮Activity并可拖动(访悬浮歌词) -
di1984HIT:
写的很好,我收藏一下。
java之动态代理模式(JDK和cglib) -
chinacssnj:
待测试,明天测,测试的结果发给大家
网络开发上传文件到服务器 -
fx_199182:
...
Android之MediaPlayer
ListView的分页显示
- 博客分类:
- Android之控件及布局
package com.anddev.ListMore.Test; import android.app.Activity; import android.os.Bundle; import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.Button; import android.widget.ListView; import android.widget.TextView; public class ListMoreTest extends Activity { ListView lv; Button btnLeft, btnRight; View.OnClickListener cl; MoreAdapter ma; String[] data = { "0","1","2","3","4","5","6","7","8","9","10", "11","12","13","14","15","16","17","18","19","20", "21","22","23","24","25","26","27","28","29","30", "31","32","33","34","35","36","37","38","39","40", "41","42","43","44","45","46","47","48","49","50", "51","52","53","54","55","56","57","58","59","60", "61","62","64","64","65","66","67","68","69","70", "71","72","73","74","75","76","77","78","79","80", "81","82","83","84","85","86","87","88","89","90", "91","92","93","94","95","96","97","98","99","100" }; //用于显示每列5个Item项。 int VIEW_COUNT = 5; //用于显示页号的索引 int index = 0; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); //加载Listview和2个Button initView(); //设置ListView的Adapter ma = new MoreAdapter(this); lv.setAdapter(ma); cl = new Button.OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()){ case R.id.btnLeft: leftView(); break; case R.id.btnRight: rightView(); break; } } }; //添加2个Button的监听事件。 btnLeft.setOnClickListener(cl); btnRight.setOnClickListener(cl); //检查2个Button是否是可用的 checkButton(); } public void initView(){ lv = (ListView)findViewById(R.id.list); btnLeft = (Button)findViewById(R.id.btnLeft); btnRight = (Button)findViewById(R.id.btnRight); } //点击左边的Button,表示向前翻页,索引值要减1. public void leftView(){ index--; //刷新ListView里面的数值。 ma.notifyDataSetChanged(); //检查Button是否可用。 checkButton(); } //点击右边的Button,表示向后翻页,索引值要加1. public void rightView(){ index++; //刷新ListView里面的数值。 ma.notifyDataSetChanged(); //检查Button是否可用。 checkButton(); } public void checkButton(){ //索引值小于等于0,表示不能向前翻页了,以经到了第一页了。 //将向前翻页的按钮设为不可用。 if(index <=0){ btnLeft.setEnabled(false); } //值的长度减去前几页的长度,剩下的就是这一页的长度,如果这一页的长度比View_Count小,表示这是最后的一页了,后面在没有了。 //将向后翻页的按钮设为不可用。 else if(data.length - index*VIEW_COUNT <= VIEW_COUNT){ btnRight.setEnabled(false); } //否则将2个按钮都设为可用的。 else { btnLeft.setEnabled(true); btnRight.setEnabled(true); } } //ListView的Adapter,这个是关键的导致可以分页的根本原因。 public class MoreAdapter extends BaseAdapter { Activity activity; public MoreAdapter(Activity a){ activity = a; } //设置每一页的长度,默认的是View_Count的值。 @Override public int getCount() { // TODO Auto-generated method stub //return data.length; //ori表示到目前为止的前几页的总共的个数。 int ori = VIEW_COUNT * index; //值的总个数-前几页的个数就是这一页要显示的个数,如果比默认的值小,说明这是最后一页,只需显示这么多就可以了 if(data.length - ori < VIEW_COUNT ){ return data.length - ori; } //如果比默认的值还要大,说明一页显示不完,还要用换一页显示,这一页用默认的值显示满就可以了。 else { return VIEW_COUNT; } } @Override public Object getItem(int position) { // TODO Auto-generated method stub return position; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { // TODO Auto-generated method stub //return addTestView(position); TextView tv = new TextView(activity); tv.setGravity(Gravity.CENTER); //TextView要显示的是当前的位置+前几页已经显示的位置个数的对应的位置上的值。 tv.setText(data[position+index*VIEW_COUNT]); return tv; } } }
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <ListView android:id="@+id/list" android:layout_width="fill_parent" android:layout_height="wrap_content" /> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="bottom" > <Button android:id="@+id/btnLeft" android:layout_width="150dip" android:layout_height="wrap_content" android:text="@string/textLeft" /> <Button android:id="@+id/btnRight" android:layout_width="150dip" android:layout_height="wrap_content" android:text="@string/textRight" /> </LinearLayout> </LinearLayout>
摘自:http://www.cnblogs.com/shang53880/archive/2011/01/26/1945587.html
发表评论
-
Android 漂亮的 Dialog (弹出框)
2012-02-13 23:35 4209在新浪微博Android客户端的开发的课程中呢要用的得自定义的 ... -
ProgressBar的圆形和长条形设置
2012-01-12 15:02 0默认的progresbar是圆形的旋转动画: <Pro ... -
把TextView中的文字添加阴影效果及Style的使用
2012-01-12 15:00 2065<TextView android:id=" ... -
GridView动态加载数据情况下,选中状态的实现
2012-01-12 14:57 1459GridView使用AdapterView动态加载数据情况下, ... -
Android中的透明属性的设置
2012-01-12 14:50 1248ui设计时,需要指定某个元素的drawable时,有时候需要告 ... -
简单实现ImageView的加边框颜色的方法
2012-01-12 14:48 2327对于一个ImageView,如果我们要加上边框,比如宽为3dp ... -
android ,点击title的ImageView弹出PopupWindow【安卓进化七】
2011-12-03 10:33 1401一、曾经做过一个项目,用的大概就是这种布局,title布局,t ... -
Android之PopupWindow弹出对话框
2011-12-03 09:40 4077Android 的 对话框常 ... -
CursorTreeAdapter 详解
2011-12-02 17:44 2183CursorTreeAdapter 通过该适配类可以用一连续的 ... -
Android 应用程序窗体显示状态操作(requestWindowFeature()的应用)
2011-12-02 09:43 755我们在开发程序是经常会需要软件全屏显示、自定义标题(使用按钮等 ... -
Android GestureDetector 手势基础
2011-12-01 16:34 12771. 当用户触摸屏幕的时候,会产生许多手势,例如dow ... -
Android GestureDetector手势识别类
2011-12-01 14:26 2763为了加强鼠标响应事件,Android提供了GestureDet ... -
android之Tabhost深入讲解二
2011-11-29 09:18 2658之前一直认为TabHost不够灵活而使用Activit ... -
android之Tabhost深入讲解一
2011-11-28 21:46 1678大家都知道Tabhost中Tabwidget的布局是图标在上, ... -
Android中的view
2011-11-21 15:02 1146View类是Android的一个超类,这个类几乎包含了所有的屏 ... -
Android自定义View之一:初探实例 .
2011-11-21 14:53 799Android自定义View实现很简单 继承View,重写构 ...
相关推荐
这是一个ListView分页显示的示例 2013.10.27
代码很清晰,很适合初学者.欢迎大家下载学习
android listview 分页显示 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.addrlistview); // 加载Listview和2个Button ...
ListView分页显示上一页和下一页,加载数据显示
主题:ListView 分页显示
android listview 分页显示例子, 利用map缓存图片, 分页显示。
这个demo主要介绍了listView的分页功能,实现了加载更多,希望可以帮助需要的同学。
很好的资源,自己写的listview与分页的综合实例,有代码和数据库。代码通过多次测试,可以正确运行。
Android Listview 分页显示与异步下载图片 按照内存剩余大小随机释放已读图片与重新下载释放的图片
一个ListView分页显示的小例子,点击ListView的某一项,该项背景色高亮
这是一个android listview分页查询显示的demo,使用sqlite数据库,然后每次显示10条,上拉加载更多数据,studio项目
在开发公司项目的时候要求制作分页显示列表就做了一个简单的实现了listview的分页显示
VB ListView 数据分页处理,vb分页例子
主题:ListView分页(带图片)显示用法案例,主题:ListView分页(带图片)显示用法案例
基于VB6+ADO+ListView制作的一个数据库分页显示程序.doc
ListView下拉刷新和分页二个功能,经测试可以运行
ListView分页显示问题,模拟是第一次把所有数据都取出来,之后每次增加显示条目。
此demo是我在其它网站看到的很好的例子,关于ListView分页加载实现,是滚动到底部加载新的,软缓存,懒加载,大家可以借鉴下,是实时加载的。
实现了 Android listView 分页功能,代码可以运行,功能完善。
DataGridView,ListView分页源代码,有4至5种方法