引用:http://www.cnblogs.com/oldfeel/archive/2012/06/01/2530584.html

<?xml version="1.0" encoding="utf-8"?><ScrollView xmlns:android="http://schemas.android.com/apk/res/android"    android:id="@+id/arc_hf_search_result"    android:layout_width="match_parent"    android:layout_height="match_parent" >    <LinearLayout        android:id="@+id/arc_hf_search_item"        android:layout_width="fill_parent"        android:layout_height="wrap_content"        android:orientation="vertical" >    </LinearLayout></ScrollView>
复制代码

ArcHFSearchResult.java

复制代码
public class ArcHFSearchResult extends Activity {    protected static final String TAG = "ArcHFSearchResult";    private ScrollView svResult;    private LinearLayout llItem;    private String[] arrayStr;    private int pageCount = 0;    private int resultCount = 10000;    private int eachCount = 3000;    private View view;    /** Called when the activity is first created. */    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        svResult = (ScrollView) findViewById(R.id.arc_hf_search_result);        llItem = (LinearLayout) findViewById(R.id.arc_hf_search_item);        svResult.setOnTouchListener(svListener);        view = svResult.getChildAt(0);        // 将要显示的10000条数据        arrayStr = new String[resultCount];        for (int i = 0; i < resultCount; i++) {            arrayStr[i] = i + "";        }        // 第一次添加数据,每次添加3000条。        AddResult();    }    class svTouchListener implements OnTouchListener {        @Override        public boolean onTouch(View v, MotionEvent event) {            switch (event.getAction()) {            case MotionEvent.ACTION_DOWN:                break;            case MotionEvent.ACTION_UP:                // 如果触发监听事件,并且有内容,并且ScrollView已经拉到底部,加载一次数据                if (svListener != null                        && view != null                        && view.getMeasuredHeight() - 20 <= svResult                                .getScrollY() + svResult.getHeight()) {                    AddResult();                }                break;            default:                break;            }            return false;        }    }    svTouchListener svListener = new svTouchListener();    /**     * 添加结果     */    protected void AddResult() {        if (eachCount * pageCount < resultCount) {            for (int i = 0; i < eachCount; i++) {                int k = i + eachCount * pageCount;                if (k >= resultCount)                    break;                TextView tv = new TextView(this);                tv.setText("hello world" + arrayStr[k]);                llItem.addView(tv);            }            pageCount++;        }    }}

更多相关文章

  1. Android应用程序安装过程源代码分析(3)
  2. Android开发——控件基础(七)ListView组件:示例代码
  3. Ubuntu 13.04 编译环境配置及android 2.3 源代码编译时出现了以
  4. Android应用程序安装过程源代码分析(4)
  5. Android拍照上传至PHP服务器并写入MySql数据库(下)
  6. 【android】当数据库需要更新时我们该怎么办?
  7. Android 如何加载大图片
  8. Android 图片加载库Glide
  9. Android平台mass storage相关代码

随机推荐

  1. android -------- MVP+DataBinding 的使
  2. Android 开发中的常用的上传下载接口
  3. Android(安卓)进程保活招式大全
  4. Android固件img文件的解包, 修改和打包的
  5. Android(安卓)4.1.2系统添加重启功能
  6. cocos2d-x 编译成android apk常见错误
  7. Android surface 3 绘制 (的时机 java层)
  8. Android实现EditText正则表达式过滤
  9. Android 通过接口的方式去调用服务里面的
  10. Android VTS学习