Commit 751075afddde569477c5a779d8ea4ceea019308d

Authored by 姚旭斌
1 parent 59f55e6b

no message

app/src/main/java/com/shunzhi/parent/adapter/ChildAdapter.java
1 package com.shunzhi.parent.adapter; 1 package com.shunzhi.parent.adapter;
2 2
  3 +
3 import android.content.Context; 4 import android.content.Context;
4 import android.view.LayoutInflater; 5 import android.view.LayoutInflater;
5 import android.view.View; 6 import android.view.View;
@@ -15,7 +16,8 @@ import com.shunzhi.parent.bean.ChildBean; @@ -15,7 +16,8 @@ import com.shunzhi.parent.bean.ChildBean;
15 * Created by Administrator on 2018/3/9 0009. 16 * Created by Administrator on 2018/3/9 0009.
16 */ 17 */
17 18
18 -public class ChildAdapter extends BaseRecyclerViewAdapter<ChildBean>{ 19 +public class ChildAdapter extends BaseRecyclerViewAdapter<ChildBean>{
  20 +
19 Context context; 21 Context context;
20 public ChildAdapter(Context context){ 22 public ChildAdapter(Context context){
21 this.context=context; 23 this.context=context;
@@ -35,7 +37,7 @@ public class ChildAdapter extends BaseRecyclerViewAdapter&lt;ChildBean&gt;{ @@ -35,7 +37,7 @@ public class ChildAdapter extends BaseRecyclerViewAdapter&lt;ChildBean&gt;{
35 37
36 public MyViewHolder(View view) { 38 public MyViewHolder(View view) {
37 super(view); 39 super(view);
38 - textView=view.findViewById(R.id.test); 40 + textView=view.findViewById(R.id.txt_childname);
39 } 41 }
40 42
41 @Override 43 @Override
app/src/main/java/com/shunzhi/parent/ui/activity/MyChildActivity.java
1 package com.shunzhi.parent.ui.activity; 1 package com.shunzhi.parent.ui.activity;
2 2
3 import android.annotation.SuppressLint; 3 import android.annotation.SuppressLint;
  4 +import android.graphics.Color;
4 import android.os.Bundle; 5 import android.os.Bundle;
5 import android.support.annotation.NonNull; 6 import android.support.annotation.NonNull;
6 import android.support.v7.widget.LinearLayoutManager; 7 import android.support.v7.widget.LinearLayoutManager;
7 -import android.support.v7.widget.RecyclerView;  
8 import android.view.View; 8 import android.view.View;
  9 +import android.view.ViewGroup;
9 import android.widget.TextView; 10 import android.widget.TextView;
10 11
11 import com.share.mvpsdk.base.BasePresenter; 12 import com.share.mvpsdk.base.BasePresenter;
@@ -15,6 +16,12 @@ import com.shunzhi.parent.adapter.ChildAdapter; @@ -15,6 +16,12 @@ import com.shunzhi.parent.adapter.ChildAdapter;
15 import com.shunzhi.parent.bean.ChildBean; 16 import com.shunzhi.parent.bean.ChildBean;
16 import com.shunzhi.parent.contract.mine.MyChildContract; 17 import com.shunzhi.parent.contract.mine.MyChildContract;
17 import com.shunzhi.parent.presenter.mine.MyChildPresenter; 18 import com.shunzhi.parent.presenter.mine.MyChildPresenter;
  19 +import com.yanzhenjie.recyclerview.swipe.SwipeMenu;
  20 +import com.yanzhenjie.recyclerview.swipe.SwipeMenuBridge;
  21 +import com.yanzhenjie.recyclerview.swipe.SwipeMenuCreator;
  22 +import com.yanzhenjie.recyclerview.swipe.SwipeMenuItem;
  23 +import com.yanzhenjie.recyclerview.swipe.SwipeMenuItemClickListener;
  24 +import com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView;
18 25
19 import java.util.List; 26 import java.util.List;
20 27
@@ -24,7 +31,7 @@ import java.util.List; @@ -24,7 +31,7 @@ import java.util.List;
24 31
25 public class MyChildActivity extends BaseMVPCompatActivity<MyChildContract.MyChildPresenter, MyChildContract.IMyChildModel> 32 public class MyChildActivity extends BaseMVPCompatActivity<MyChildContract.MyChildPresenter, MyChildContract.IMyChildModel>
26 implements MyChildContract.IMyChildView, View.OnClickListener { 33 implements MyChildContract.IMyChildView, View.OnClickListener {
27 - RecyclerView child_recycle; 34 + SwipeMenuRecyclerView child_recycle;
28 TextView back; 35 TextView back;
29 ChildAdapter childAdapter; 36 ChildAdapter childAdapter;
30 37
@@ -46,6 +53,16 @@ public class MyChildActivity extends BaseMVPCompatActivity&lt;MyChildContract.MyChi @@ -46,6 +53,16 @@ public class MyChildActivity extends BaseMVPCompatActivity&lt;MyChildContract.MyChi
46 53
47 private void initRecyclerView() { 54 private void initRecyclerView() {
48 child_recycle.setLayoutManager(new LinearLayoutManager(this)); 55 child_recycle.setLayoutManager(new LinearLayoutManager(this));
  56 + child_recycle.smoothOpenRightMenu(0);
  57 + child_recycle.setSwipeMenuCreator(swipeMenuCreator);
  58 + child_recycle.setSwipeMenuItemClickListener(new SwipeMenuItemClickListener() {
  59 + @Override
  60 + public void onItemClick(SwipeMenuBridge menuBridge) {
  61 + int adapterPosition = menuBridge.getAdapterPosition();
  62 + childAdapter.remove(adapterPosition);
  63 + }
  64 + });
  65 +
49 mPresenter.loadChildList(); 66 mPresenter.loadChildList();
50 } 67 }
51 68
@@ -61,9 +78,28 @@ public class MyChildActivity extends BaseMVPCompatActivity&lt;MyChildContract.MyChi @@ -61,9 +78,28 @@ public class MyChildActivity extends BaseMVPCompatActivity&lt;MyChildContract.MyChi
61 78
62 @Override 79 @Override
63 public void updateChilsList(List<ChildBean> list) { 80 public void updateChilsList(List<ChildBean> list) {
64 - childAdapter=new ChildAdapter(this); 81 + childAdapter = new ChildAdapter(this);
65 childAdapter.addAll(list); 82 childAdapter.addAll(list);
66 child_recycle.setAdapter(childAdapter); 83 child_recycle.setAdapter(childAdapter);
67 84
68 } 85 }
  86 +
  87 + private SwipeMenuCreator swipeMenuCreator = new SwipeMenuCreator() {
  88 + @Override
  89 + public void onCreateMenu(SwipeMenu swipeLeftMenu, SwipeMenu swipeRightMenu, int viewType) {
  90 + int height = ViewGroup.LayoutParams.MATCH_PARENT;
  91 + int width = ViewGroup.LayoutParams.WRAP_CONTENT;
  92 + SwipeMenuItem deleteItem = new SwipeMenuItem(mContext)
  93 + .setBackgroundColor(Color.RED)
  94 + .setText(" 解除绑定 ") // 文字。
  95 + .setTextColor(Color.WHITE) // 文字颜色。
  96 + .setTextSize(20)
  97 + .setWidth(width)
  98 + .setHeight(height); // 文字大小。
  99 + swipeRightMenu.addMenuItem(deleteItem);// 添加一个按钮到右侧侧菜单。
  100 +
  101 + }
  102 + };
  103 +
  104 +
69 } 105 }
app/src/main/res/layout/activity_mychild.xml
@@ -7,14 +7,13 @@ @@ -7,14 +7,13 @@
7 > 7 >
8 8
9 <include layout="@layout/top"/> 9 <include layout="@layout/top"/>
10 -<android.support.v7.widget.RecyclerView  
11 - android:id="@+id/child_recycle"  
12 - android:layout_width="match_parent"  
13 - android:layout_height="wrap_content"  
14 - android:layout_weight="1"  
15 - >  
16 -  
17 -</android.support.v7.widget.RecyclerView> 10 + <com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView
  11 + android:id="@+id/child_recycle"
  12 + android:layout_width="match_parent"
  13 + android:layout_height="wrap_content"
  14 + android:layout_weight="1"
  15 + >
  16 + </com.yanzhenjie.recyclerview.swipe.SwipeMenuRecyclerView>
18 17
19 <TextView 18 <TextView
20 android:layout_width="match_parent" 19 android:layout_width="match_parent"