三题第二问 谢谢酷派大神f1问题

我来说两句:验证码 &&请照此输入(点击图片刷新验证码)&&&&最多输入10000个字符其它答案:共1条你需要才可以查看回复。没有帐号?&&0人赞同
相关内容等待您来回答012009编辑推荐财税资讯会计中心税务中心财税问答政策法规共享中心产品服务会计人生互动交流论坛精华系统消息3秒后窗口关闭& ListView分页加载数据
ListView分页加载数据
对于ListView分页加载数据,是正常情况下是非常有必要。一般对于少量的数据一次性把全部数据加载到ListView中显示,对于数据量多比较大,特别在资源有限的手机设备中更有重要,由用户去点击加载想要数据更为合适。在一些博客上看到关于ListView分页加载,但不太全面,实用性不高,因此我模拟正常情况下ListView分页加载,对于有方面帮助的朋友肯定有用,由于本人技术有限,可能存在些问题,欢迎指正,谢谢!
先看效果吧,
2. java代码:MainActivity.java
* ListView分页加载数据
* @author zhangkai281
public class MainActivity extends Activity {
private ListView listV
private List&Map&String,Object&&
private listViewA
//分页加载的数据的数量
private int pageSize=10;
private final int pageType=1;
//查看更多
private TextView moreTextV
//正在加载进度条
private LinearLayout loadProgressB
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_page);
listView=(ListView)findViewById(R.id.lv_id);
//第一个参数:1起始数
第二个参数:显示的数目
data=InitValue.initValue(1,15);
//在ListView中添加"加载更多"
addPageMore();
//添加"加载更多"一定要在设置Adapter之前
adapter=new listViewAdapter();
listView.setAdapter(adapter);
private class listViewAdapter extends BaseAdapter{
int count=data.size();
public int getCount() {
public Object getItem(int position) {
public long getItemId(int position) {
public View getView(int position, View convertView, ViewGroup parent) {
View view=LayoutInflater.from(MainActivity.this).inflate(R.layout.list_page_item, null);
TextView title=(TextView)view.findViewById(R.id.tv_id);
TextView text=(TextView)view.findViewById(R.id.title_id);
title.setText(data.get(position).get("title").toString());
text.setText(data.get(position).get("text").toString());
* 加载下一页的数据
* @param pageStart
* @param pageSize
private void chageListView(int pageStart,int pageSize){
List&Map&String,Object&& data=InitValue.initValue(pageStart,pageSize);
for (Map&String, Object& map : data) {
this.data.add(map);
* 在ListView中添加"加载更多"
private void addPageMore(){
View view=LayoutInflater.from(this).inflate(R.layout.list_page_load, null);
moreTextView=(TextView)view.findViewById(R.id.more_id);
loadProgressBar=(LinearLayout)view.findViewById(R.id.load_id);
moreTextView.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
//隐藏"加载更多"
moreTextView.setVisibility(View.GONE);
//显示进度条
loadProgressBar.setVisibility(View.VISIBLE);
new Thread(new Runnable() {
public void run() {
//休眠3秒,用于模拟网络操作时间
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
//加载模拟数据:下一页数据, 在正常情况下,上面的休眠是不需要,直接使用下面这句代码加载相关数据
chageListView(data.size(),pageSize);
Message mes=handler.obtainMessage(pageType);
handler.sendMessage(mes);
}).start();
listView.addFooterView(view);
private Handler handler=new Handler(){
public void handleMessage(Message msg) {
switch (msg.what) {
case pageType:
//改变适配器的数目
adapter.count += pageS
//通知适配器,发现改变操作
adapter.notifyDataSetChanged();
//再次显示"加载更多"
moreTextView.setVisibility(View.VISIBLE);
//再次隐藏“进度条”
loadProgressBar.setVisibility(View.GONE);
super.handleMessage(msg);
模拟数据,通常是通过网络取得服务器的数据,显示出来,得向服务传递参数包括分页相关,当时启起行数,每页显示多行数据。也可以加载本地的SQLite库中的数据。加载网络的比较比吧,以下只是模拟数据:
public class InitValue {
public static int page=1;
* 模拟数据分页加载,
* @param pageStart
* @param pageSize
每页显示数目
public static List&Map&String,Object&& initValue(int pageStart,int pageSize){
Map&String,Object&
List&Map&String,Object&& list=new ArrayList&Map&String,Object&&();
for(int i=0;i&pageSi++){
map=new HashMap&String,Object&();
map.put("text", "zhangkai281发表文章");
map.put("title", page+"_ListView分页显示");
list.add(map);
4. 布局文件:main.xml:
&?xml version="1.0" encoding="utf-8"?&
&ScrollView android:layout_width="fill_parent" xmlns:android="/apk/res/android"
android:layout_height="wrap_content" android:scrollbars="vertical"&
&LinearLayout
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"&
&TextView android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="@string/app_name" /&
&ViewFlipper android:id="@+id/vf_id" android:layout_width="fill_parent"
android:layout_height="wrap_content" /&
&/LinearLayout&
&/ScrollView&
5. 布局文件:list_page.xml:
&?xml version="1.0" encoding="utf-8"?&
&LinearLayout xmlns:android="/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent"&
&ListView android:id="@+id/lv_id" android:layout_width="fill_parent"
android:layout_height="wrap_content"/&
&/LinearLayout&
6. 布局文件:list_page_load.xml
&?xml version="1.0" encoding="utf-8"?&
&LinearLayout xmlns:android="/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" android:gravity="center_horizontal"
android:paddingTop="13dp" android:paddingBottom="13dp"&
&TextView android:id="@+id/more_id" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:text="查看更多..."
android:textSize="25dp" android:gravity="center_horizontal"/&
&LinearLayout android:id="@+id/load_id" android:orientation="horizontal"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:visibility="gone"&
&ProgressBar android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_gravity="center_horizontal" /&
&TextView android:layout_width="wrap_content" android:layout_height="fill_parent"
android:gravity="center_vertical" android:layout_marginLeft="10dp"
android:text="正在加载..." android:textSize="20dp"/&
&/LinearLayout&
&/LinearLayout&
7. 还有此小xml加有列出,比较简单,此处省略,
希望此文章对朋友有所帮助,谢谢!
本文固定链接:
[上一篇][下一篇]
最新文章随机精彩热门排行
日志总数:3902 篇
评论总数:27048 评
标签数量:4473 个
链接总数:4 条
建站日期:
运行天数:1177 天中国福文化网 福文化|福字|福|请福|送福|得福|造福文章评论_成华区图书馆
&&&&&&栏目导航&当前位置:&&评论:
成华区图书馆举办“看不见的手”少儿财商讲座
点击查看原文
&&&&&该信息当前没有评论!
*电子邮件:
*评论内容:
&&&&&&&&&&&&&&&&&
版权所有:
地址:成华区图书馆 邮编:610051
电话:&邮箱: &QQ:
页面执行时间:.000毫秒mtDropDownSet.registry = [];
function mtDropDownSet(iDirection, iLeft, iTop, iReferencePoint) {
this.addMenu = addM
this.showMenu = showM
this.hideMenu = hideM
this.hide =
var menus = [];
var _this =
var current =
this.index = mtDropDownSet.registry.
mtDropDownSet.registry[this.index] =
function addMenu(oActuator) {
var m = new mtDropDown(oActuator, iDirection, iLeft, iTop, iReferencePoint, this);
menus[menus.length] =
function showMenu(oMenu) {
if (oMenu != current) {
if (current != null) hide(current);
current = oM
oMenu.show();
cancelHide(oMenu);
function hideMenu(oMenu) {
if (current == oMenu && oMenu.isOpen) {
if (!oMenu.hideTimer) scheduleHide(oMenu);
function scheduleHide(oMenu) {
oMenu.onqueue();
oMenu.hideTimer = window.setTimeout("mtDropDownSet.registry[" + _this.index + "].hide(mtDropDown.registry[" + oMenu.index + "])", mtDropDown.hideDelay);
function cancelHide(oMenu) {
if (oMenu.hideTimer) {
window.clearTimeout(oMenu.hideTimer);
oMenu.hideTimer =
function hide(oMenu) {
if (!oMenu && current) oMenu =
if (oMenu && current == oMenu && oMenu.isOpen) {
cancelHide(oMenu);
oMenu.hideTimer =
oMenu.hide();
function mtDropDownItem(sText, sUrl, oParent) {
this.toString = toS
this.text = sT
this.url = sU
this.parentMenu = oP
function toString(bDingbat) {
var sDingbat = bDingbat ? mtDropDown.dingbatOff : mtDropDown.spacerG
var iEdgePadding = mtDropDown.itemPadding + mtDropDown.menuP
var sPaddingLeft = "padding:" + mtDropDown.itemPadding + " padding-left:" + iEdgePadding + ""
var sPaddingRight = "padding:" + mtDropDown.itemPadding + " padding-right:" + iEdgePadding + ""
return '' +
sText + '' +
function Accelimation(from, to, time, zip) {
if (typeof zip == "undefined") zip = 0;
if (typeof unit == "undefined") unit = "px";
this.zip = -
this.unit =
this.timer =
this.onend = new Function();
this.onframe = new Function();
Accelimation.prototype.start = function() {
this.t0 = new Date().getTime();
this.t1 = this.t0 + this.
var dx = this.x1 - this.x0;
this.c1 = this.x0 + ((1 + this.zip) * dx / 3);
this.c2 = this.x0 + ((2 + this.zip) * dx / 3);
Accelimation._add(this);
Accelimation.prototype.stop = function() {
Accelimation._remove(this);
Accelimation.prototype._paint = function(time) {
if (time < this.t1) {
var elapsed = time - this.t0;
this.onframe(Accelimation._getBezier(elapsed/this.dt,this.x0,this.x1,this.c1,this.c2));
else this._end();
Accelimation.prototype._end = function() {
Accelimation._remove(this);
this.onframe(this.x1);
this.onend();
Accelimation._add = function(o) {
var index = this.instances.
this.instances[index] =
if (this.instances.length == 1) {
this.timerID = window.setInterval("Accelimation._paintAll()", this.targetRes);
Accelimation._remove = function(o) {
for (var i = 0; i < this.instances. i++) {
if (o == this.instances[i]) {
this.instances = this.instances.slice(0,i).concat( this.instances.slice(i+1) );
if (this.instances.length == 0) {
window.clearInterval(this.timerID);
this.timerID =
Accelimation._paintAll = function() {
var now = new Date().getTime();
for (var i = 0; i < this.instances. i++) {
this.instances[i]._paint(now);
Accelimation._B1 = function(t) { return t*t*t }
Accelimation._B2 = function(t) { return 3*t*t*(1-t) }
Accelimation._B3 = function(t) { return 3*t*(1-t)*(1-t) }
Accelimation._B4 = function(t) { return (1-t)*(1-t)*(1-t) }
Accelimation._getBezier = function(percent,startPos,endPos,control1,control2) {
return endPos * this._B1(percent) + control2 * this._B2(percent) + control1 * this._B3(percent) + startPos * this._B4(percent);
Accelimation.instances = [];
Accelimation.targetRes = 10;
Accelimation.timerID =
&&您的位置&& >> 评论:
中共浏阳市中医医院委员会关于成立医院党的群众路线教育实践活动领导小组的通知
该信息当前没有评论!

我要回帖

更多关于 酷派大神f2耳机问题 的文章

 

随机推荐