zoukankan      html  css  js  c++  java
  • 分页加载

    package com.zcp.fyjz;

    import java.util.ArrayList;
    import java.util.List;

    import android.os.Bundle;
    import android.app.Activity;
    import android.view.Menu;
    import android.widget.AbsListView;
    import android.widget.AbsListView.OnScrollListener;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
    import android.widget.Toast;

    public class MainActivity extends Activity {

    private ListView listview;
    private List<String> list;
    private ArrayAdapter<String> adapter;
    private Boolean flag=false;
    private int i=1;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    listview=(ListView)findViewById(R.id.listview);
    list=new ArrayList<String>();
    data("");
    adapter=new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,list);
    listview.setAdapter(adapter);
    listview.setOnScrollListener(new OnScrollListener() {

    /* (non-Javadoc)
    *
    * SCROLL_STATE_FLING 手指做出抛的动作
    * SCROLL_STATE_IDLE 停止滚动
    * SCROLL_STATE_TOUCH_SCROLL 手指在屏幕上,屏幕滚动
    * @see android.widget.AbsListView.OnScrollListener#onScrollStateChanged(android.widget.AbsListView, int)
    */
    @Override
    public void onScrollStateChanged(AbsListView view, int scrollState) {
    if(flag&&scrollState==OnScrollListener.SCROLL_STATE_IDLE){
    Toast.makeText(getApplicationContext(), "正在拼命加载数据。。。", 1).show();
    data("Android"+i);
    i++;
    adapter.notifyDataSetChanged();
    }

    }

    @Override
    public void onScroll(AbsListView view, int firstVisibleItem,
    int visibleItemCount, int totalItemCount) {
    flag=((firstVisibleItem+visibleItemCount)==totalItemCount);

    }
    });
    }

    private void data(String p) {
    for (int i = 0; i <30; i++) {
    list.add(p+" data"+i);
    }

    }

    }

  • 相关阅读:
    开启gpu加速的高性能移动端相框组件!
    一看就懂得移动端rem布局、rem如何换算
    加密算法
    YDNKJS 笔记
    JavaScript函数
    测试下
    console前端代码自动删除QQ空间我的说说
    前端规范
    解决方案
    重读js高程笔记二
  • 原文地址:https://www.cnblogs.com/hnpy/p/5488243.html
Copyright © 2011-2022 走看看