网站建设资讯

NEWS

网站建设资讯

Android编程实现ListView滚动提示等待框功能示例

本文实例讲述了Android编程实现ListView滚动提示等待框功能。分享给大家供大家参考,具体如下:

成都创新互联专注于企业成都全网营销、网站重做改版、和政网站定制设计、自适应品牌网站建设、H5开发购物商城网站建设、集团公司官网建设、外贸营销网站建设、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为和政等各大城市提供网站开发制作服务。

其实原理很简单,只需要设置监听listview的滚动事件即可

file1:

package cn.stay.activity;
import java.util.ArrayList;
import java.util.List;
import com.aoran.R;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
/**
 * @author riddlezhang
 * 滚动listview提示等待框
 */
public class ListView_sep extends Activity implements OnScrollListener {
  private List list = new ArrayList();
  private ListView listv01;
  private MyAdapter adapter;
  private int current_page = 2;
  ProgressBar progressBar;
  private LinearLayout bottom_linear;
  private int lastItem;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    listv01 = (ListView) findViewById(R.id.listv01);
    bottom_linear=(LinearLayout) findViewById(R.id.bottom_linear);
    for (int i = 0; i < 100; i++) {
      list.add("i="+i);
    }
    adapter = new MyAdapter(ListView_sep.this, list);
    listv01.setAdapter(adapter);
//   listv01.setSelection(getSingerStrs().size()-1); 设置每次最后一行被选中
    listv01.setOnScrollListener(this);
  }
  @Override
  public void onScrollStateChanged(AbsListView view, int scrollState) {
    if (lastItem==adapter.count && scrollState == OnScrollListener.SCROLL_STATE_IDLE) {
      if ((list.size() - current_page * 10) > 0) {
        bottom_linear.setVisibility(View.VISIBLE);
        if ((list.size() - current_page * 10) >= 10) {
          adapter.count += 10;
        } else {
          adapter.count += (list.size() - current_page * 10);
        }
        current_page++;
        adapter.notifyDataSetChanged();
//       bottom_linear.setVisibility(View.GONE);
      }
    }
  }
  @Override
  public void onScroll(AbsListView view, int firstVisibleItem,
      int visibleItemCount, int totalItemCount) {
      lastItem=firstVisibleItem+visibleItemCount;
  }
}

file2:

package cn.stay.activity;
import java.util.List;
import com.aoran.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
public class MyAdapter extends BaseAdapter{
  private Context mContext;
  private List list;
  public int count=20;
  private ViewHolder holder;
  public MyAdapter(Context mContext,List list) {
    this.mContext=mContext;
    this.list=list;
  }
  @Override
  public int getCount() {
    return count;
  }
  @Override
  public Object getItem(int position) {
    // TODO Auto-generated method stub
    return list.get(position);
  }
  @Override
  public long getItemId(int position) {
    return position;
  }
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    if(convertView==null || convertView.getTag()==null){
      convertView=LayoutInflater.from(mContext).inflate(R.layout.adapter,null);
      holder = new ViewHolder();
      holder.adapter_tv=(TextView) convertView.findViewById(R.id.adapter_tv);
      convertView.setTag(holder);
      }else{
        holder=(ViewHolder) convertView.getTag();
      }
    holder.adapter_tv.setText(list.get(position));
    return convertView;
  }
  private class ViewHolder{
    private TextView adapter_tv;
  }
}

file3:

main.xml

<?xml version="1.0" encoding="utf-8"?>

  
    
    
  
  


更多关于Android相关内容感兴趣的读者可查看本站专题:《Android视图View技巧总结》、《Android布局layout技巧总结》、《Android图形与图像处理技巧总结》、《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android多媒体操作技巧汇总(音频,视频,录音等)》、《Android基本组件用法总结》及《Android控件用法总结》

希望本文所述对大家Android程序设计有所帮助。


分享标题:Android编程实现ListView滚动提示等待框功能示例
链接地址:http://njwzjz.com/article/ggidci.html