设为首页 加入收藏

TOP

Android 滑动加载数据(一)
2014-11-24 03:24:53 来源: 作者: 【 】 浏览:5
Tags:Android 滑动 加载 数据

package com.ScrollListView;


public class EndLessActivity extends ListActivity implements OnScrollListener {

Aleph0 adapter = new Aleph0();
int mProgressStatus = 0 ;
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);


setListAdapter(adapter);
getListView().setOnScrollListener( this );
}

public void onScroll(AbsListView view,
int firstVisible, int visibleCount, int totalCount) {

boolean loadMore = /* maybe add a padding */
firstVisible + visibleCount >= totalCount;

if (loadMore) {
adapter.count += visibleCount; // or any other amount
adapter.notifyDataSetChanged();
}
}

public void onScrollStateChanged(AbsListView v, int s) { }

class Aleph0 extends BaseAdapter {
int count = 40 ; /* starting amount */

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(EndLessActivity. this );
view.setText( " entry " + pos);
return view;
}
}



}


listview下部是按钮控制:


package com.ScrollListView;


import android.app.ListActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.AbsListView.OnScrollListener;


public class EndLessActivity extends ListActivity {

Aleph0 adapter = new Aleph0();
int mProgressStatus = 0 ;

protected void on

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇Android开发之ListView页眉页脚效.. 下一篇Android 命令行手动编译打包过程图

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Shell脚本:Linux Sh (2025-12-25 05:50:11)
·VMware虚拟机安装Lin (2025-12-25 05:50:08)
·Linux学习教程,Linu (2025-12-25 05:50:06)
·工业机器人TCP校准中 (2025-12-25 05:19:17)
·opc 通讯协议与 TCP (2025-12-25 05:19:15)