@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setData();
showList(apk_list);
}
MyAdapter adapter;
ReFlashListView listview;
private void showList(ArrayList<ApkEntity> apk_list) {
if (adapter == null) {
listview = (ReFlashListView) findViewById(R.id.listview);
listview.setInterface(this);
adapter = new MyAdapter(this, apk_list);
listview.setAdapter(adapter);
} else {
adapter.onDateChange(apk_list);
}
}
private void setData() {
apk_list = new ArrayList<ApkEntity>();
for (int i = 0; i < 10; i++) {
ApkEntity entity = new ApkEntity();
entity.setName("默认数据");
entity.setDes("这是一个神奇的应用");
entity.setInfo("50w用户");
apk_list.add(entity);
}
}
private void setReflashData() {
for (int i = 0; i < 2; i++) {ApkEntity entity = new ApkEntity();
entity.setName("刷新数据");
entity.setDes("这是一个神奇的应用");
entity.setInfo("50w用户");
apk_list.add(0,entity);
}
}
@Override
public void onReflash() {
// TODO Auto-generated method stub\
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
//获取最新数据
setReflashData();
//通知界面显示
showList(apk_list);
//通知listview 刷新数据完毕;
listview.reflashComplete();
}
}, 2000);
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dip"
android:paddingTop="10dip" >
<LinearLayout
android:id="@+id/layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:id="@+id/tip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下拉可以刷新!" />
<TextView
android:id="@+id/lastupdate_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<ImageView
android:id="@+id/arrow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/layout"
android:layout_marginRight="20dip"
android:src="@drawable/pull_to_refresh_arrow" />
<ProgressBar
android:id="@+id/progress"
style="?android:attr/progressBarStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/layout"
android:layout_marginRight="20dip"
android:visibility="gone" />
</RelativeLayout>
</LinearLayout>