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);
}
}
}
//xml配置
<ListView
android:id="@+id/listview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
/>