<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="MergeRootFrame" >
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_container"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</ListView>
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
package hi.xiaoyu.swiperefreshlayout;
import hi.xiaoyu.swiperefreshlayout.adapter.TestAdapter;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v4.widget.SwipeRefreshLayout.OnRefreshListener;
import android.widget.ListView;
public class MainActivity extends Activity implements OnRefreshListener {
private SwipeRefreshLayout swipeLayout;
private ListView listView;
private List<String> listDatas;
private TestAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipe_container);
listView = (ListView) findViewById(R.id.list);
swipeLayout.setOnRefreshListener(this);
swipeLayout.setColorSchemeResources(android.R.color.holo_orange_dark,
android.R.color.holo_green_light,
android.R.color.holo_orange_light,
android.R.color.holo_red_light);
listDatas = new ArrayList<String>();
for (int i = 0; i < 10; i++) {
listDatas.add("item" + i);
}
adapter = new TestAdapter(this, listDatas, R.layout.test_item);
listView.setAdapter(adapter);
}
public void onRefresh() {
new Handler().postDelayed(new Runnable() {
public void run() {
swipeLayout.setRefreshing(false);
listDatas.addAll(listDatas);
adapter.notifyDataSetChanged();
}
}, 3000);
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity" > <com.handmark.pulltorefresh.library.PullToRefreshListView android:id="@+id/pull_refresh_list" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </RelativeLayout>
public boolean isHeaderShown() {
return getHeaderLayout().isShown();
}
public boolean isFooterShown() {
return getFooterLayout().isShown();
}
public class MainActivity extends ListActivity {
private PullToRefreshListView mPullToRefreshListView;
private LinkedList<String> mItemList;
private ArrayAdapter<String> adapter;
private Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
context = this;
initData();
adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mItemList);
//初始化控件
mPullToRefreshListView = (PullToRefreshListView)findViewById(R.id.pull_refresh_list);
ListView mListView = mPullToRefreshListView.getRefreshableView();
mListView.setAdapter(adapter);
//设置pull-to-refresh模式为Mode.Both
mPullToRefreshListView.setMode(Mode.BOTH);
//设置上拉下拉事件
mPullToRefreshListView.setOnRefreshListener(new OnRefreshListener<ListView>() {
@Override
public void onRefresh(PullToRefreshBase<ListView> refreshView) {
if (refreshView.isHeaderShown()){
Toast.makeText(context, "下拉刷新",Toast.LENGTH_SHORT).show();
//下拉刷新 业务代码
}else {
Toast.makeText(context, "上拉加载更多",Toast.LENGTH_SHORT).show();
//上拉加载更多 业务代码
}
}
});
}
private void initData(){
//初始化数据
mItemList = new LinkedList<String>();
mItemList.addAll(Arrays.asList(data));
}
private String[] data = new String[]{"data1","data2","data3","data4","data5","data6",
"data1","data2","data3","data4","data5","data6"};
}
if (refreshView.isHeaderShown()){
Toast.makeText(context, "下拉刷新",Toast.LENGTH_SHORT).show();
//下拉刷新 业务代码
}else {
Toast.makeText(context, "上拉加载更多",Toast.LENGTH_SHORT).show();
//上拉加载更多 业务代码
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有