implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0"//下拉刷新
implementation 'com.baoyz.swipemenulistview:library:1.3.0'//左滑删除
==============
---------------------------
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
--------------------------------
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="60dp"
android:layout_marginTop="40dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_below="@+id/ldxxdf"
android:orientation="horizontal">
<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">
<com.baoyz.swipemenulistview.SwipeMenuListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list_item">
</ListView>
<TextView
android:id="@+id/empty_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:padding="20dp"
android:text="数据为空,请添加"
android:textColor="#000000"
android:textSize="16sp"/>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
-----------------------------------------------------------------------------
private SwipeMenuListView yhpg_reclv;//左滑删除
yhpg_reclv =(SwipeMenuListView) findViewById(R.id.listView);//用了左划控件
yhpg_reclv.setEmptyView(findViewById(R.id.empty_tv));//设置为空提示
/**
* 创建每个item的侧滑选项//左划菜单
*/
private void createMenu(){
SwipeMenuCreator creator = new SwipeMenuCreator() {
@Override
public void create(SwipeMenu menu) {
// 添加
SwipeMenuItem addItem = new SwipeMenuItem(BjlistLocalActivity.this);
addItem.setBackground(new ColorDrawable(Color.rgb(0xC9, 0xC9,0xCE)));
addItem.setWidth(dp2px(90));
addItem.setTitle("添加");
addItem.setTitleSize(20);
addItem.setTitleColor(Color.WHITE);
menu.addMenuItem(addItem);
// 删除
SwipeMenuItem deleteItem = new SwipeMenuItem(BjlistLocalActivity.this);
deleteItem.setBackground(new ColorDrawable(Color.rgb(0xF9,0x3F, 0x25)));
deleteItem.setWidth(dp2px(90));
deleteItem.setTitle("删除");
deleteItem.setTitleSize(20);
deleteItem.setTitleColor(Color.WHITE);
menu.addMenuItem(deleteItem);
}
};
// 添加到SwipeMenuListView
yhpg_reclv.setMenuCreator(creator);
}
public int dp2px(float dipValue) {
final float scale = this.getResources().getDisplayMetrics().density;
return (int) (dipValue * scale + 0.5f);
}
//左划删除事件
void delmeulister(){
yhpg_reclv.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
if(index == 0){
// todo 添加
Toast.makeText(getApplicationContext(), "打开第" + lists.get(position).getTmbid() + "个条目", Toast.LENGTH_SHORT).show();
}else{
// todo 删除
Toast.makeText(getApplicationContext(), "打开第" + lists.get(position).getTmbid() + "个条目", Toast.LENGTH_SHORT).show();
}
// false : close the menu; true : not close the menu
return false;
}
});
}
================
//下拉
SwipeRefreshLayout swipeRefreshLayout;//1下接
---------------------------------------------------------
<com.baoyz.swipemenulistview.SwipeMenuListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
----------------------------------------------------------
//下接刷新3
swipeRefreshLayout.setColorSchemeResources(android.R.color.holo_blue_bright,
android.R.color.holo_green_light, android.R.color.holo_orange_light);
//给swipeRefreshLayout绑定刷新监听
swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
//设置2秒的时间来执行以下事件
new Handler().postDelayed(new Runnable() {
public void run() {
getshinfor();
PDadapter.notifyDataSetChanged();
swipeRefreshLayout.setRefreshing(false);
}
}, 2000);
}
});