1:适配器
...extends SwipeMenuAdapter
public static final int HeaderType = 0;
public static final int ContentType = 1;
public static final int FooterTyoe = 2;
final int HeaderCount = 1;
final int FooterCount = 1;
@Override public View onCreateContentView(ViewGroup parent, int viewType) { if(viewType == HeaderType){
return layoutInflater.inflate(layout,parent,false);
else if(viewType == ContentType)return layoutInflater.inflate(layout,parent, false); else return layoutInflater.inflate(layout,parent, false );
@Override public RecyclerView.ViewHolder onCompatCreateViewHolder(View realContentView, int viewType) {
if(viewType == HeaderType)
return new HeaderView(realContentView);
else
if(viewType ==
ContentType)
return new ContentView(realContentView);
else
return new FooterView(realContentView);}
@Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if(holder instanceof HeaderView){}
else if(holder instanceof ContentView){}
else{}
}
@Override public int getItemViewType(int position) { if(position == getItemCount() - 1 && getItemCount() != 0) return FooterTyoe;
else if(position == 0 && getItemCount() != 0)
return HeaderType; else return ContentType; } @Override public int getItemCount() { return membersCode.content.size() + HeaderCount + FooterCount; }
}
2 添加菜单:
private SwipeMenuCreator swipeMenuCreator = new SwipeMenuCreator() { @Override public void onCreateMenu(SwipeMenu leftMenu, SwipeMenu rightMenu, int viewType) { if(viewType == ContentType) { SwipeMenuItem deleteItem = new SwipeMenuItem(getApplicationContext()) rightMenu.addMenuItem(deleteItem); // 在左侧添加一个菜单。 }else if(viewType == HeaderType){}
else {}
}
};