private XListViewmyxlist;
private List list;
Handlerhandler=newHandler() {
@Override
public voidhandleMessage(Message msg) {
Myad myad =newMyad();
myxlist.setAdapter(myad);
myad.notifyDataSetChanged();
closeMyXlist();
}
private voidcloseMyXlist() {
myxlist.stopLoadMore();
myxlist.stopRefresh();
}
};
@Override
protected voidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
myxlist= (XListView) findViewById(R.id.myxlist);
list=newArrayList<>();
for(inti=0;i<30;i++){
list.add("asd");
}
myxlist.setPullLoadEnable(true);
myxlist.setPullRefreshEnable(true);
myxlist.setXListViewListener(this);
}
@Override
public voidonRefresh() {
myxlist.postDelayed(newRunnable() {
@Override
public voidrun() {
list.add(0,"asddasdasdasdasdas上面dasdasdasdasdasdasdasdassdass");
handler.sendEmptyMessage(0);
}
},1000);
}
@Override
public voidonLoadMore() {
myxlist.postDelayed(newRunnable() {
@Override
public voidrun() {
list.add("asddassdasdasdas下面ass");
handler.sendEmptyMessage(0);
}
},1000);
}
classMyadextendsBaseAdapter{
@Override
public intgetCount() {
returnlist.size();
}
@Override
publicObjectgetItem(inti) {
return null;
}
@Override
public longgetItemId(inti) {
return0;
}
@Override
publicViewgetView(inti,View view,ViewGroup viewGroup) {
view = View.inflate(MainActivity.this,R.layout.item,null);
TextView textView = (TextView) view.findViewById(R.id.textvew);
textView.setText(list.get(i));
returnview;
}
}
}