package com.example.d_12;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AbsListView.OnScrollListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast;
public class MainActivity extends Activity {
private ListView listView;
private Mydapater mydapater;
int index = 0 ;
int num = 20 ;
private List<Student> list = new ArrayList<Student>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// 初始化
initView();
// 测试数据
//进度条
View view = View.inflate(this, R.layout.jin, null);
listView.addFooterView(view);
add();
listView.setOnScrollListener(new OnScrollListener() {
@Override
public void onScrollStateChanged(AbsListView view, int scrollState) {
if (scrollState==OnScrollListener.SCROLL_STATE_IDLE) {
//显示的最后一条条目
if (listView.getLastVisiblePosition()==list.size()) {
index= index+num;
add();
}
}
}
@Override //0
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
}
});
}
private void add() {
for (int i = index; i < index+num; i++) {
list.add(new Student(i+"中国"+i));
}
if (mydapater==null) {
mydapater = new Mydapater(list, this);
listView.setAdapter(mydapater);
} else {
mydapater.notifyDataSetChanged();
}
}
private void initView() {
listView = (ListView) findViewById(R.id.listv);
}
}
UI_条目滑动监听
最新推荐文章于 2020-05-22 22:06:31 发布