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.LinearLayout;import android.widget.ProgressBar;import android.widget.TextView;import android.widget.AbsListView.OnScrollListener;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 onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         LinearLayout searchLayout = new LinearLayout(this);        searchLayout.setOrientation(LinearLayout.HORIZONTAL);                           Button textView = new Button(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);             textView.setOnClickListener(new Button.OnClickListener()                {        @Override                       public void onClick(View v)               {                          adapter.count += 10;                   adapter.notifyDataSetChanged();                  }                   });                                    setListAdapter(adapter);          //getListView().setOnScrollListener(this);     }    /*public void onScroll(AbsListView view,         int firstVisible, int visibleCount, int totalCount) {          boolean loadMore =              firstVisible + visibleCount >= totalCount;          if(loadMore) {             adapter.count += visibleCount;              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;         }     } }

更多相关文章

  1. android 多项对话框
  2. Android(安卓)VNC Server on G1 (PC 远程控制 Android(安卓)手机
  3. Android(安卓)中SpannableStringBuilder控制局部文本颜色和点击
  4. android sqlite 增删查 demo
  5. Android(安卓)获取imu数据
  6. android 列表对话框
  7. Android音频系统之音量控制详解(Android(安卓)5.1)
  8. Android控制闪光灯的方法(打开与关闭)
  9. Android中的UI界面控制方式和自定义View

随机推荐

  1. Mac无法编译android
  2. 31、android打开文件夹并列出里面的文件
  3. Android 之 网络访问服务器,解析JSON数据
  4. Android移动开发 打包 apk
  5. Bugly Android 这个错误 Cleartext HTTP
  6. SmallActivity创建
  7. tabhost放到底部显示
  8. android 常用资料
  9. Android线性布局(Linear Layout)
  10. Android定制--------自定义关机时间