SwipeMenuListViewの横滑りmenuの内容修正について
5552 ワード
ソースコードを見てsetAdapter(SwipeMenuAdapter)の書き換え方法を知った
@Override
public void setAdapter(ListAdapter adapter) {
super.setAdapter(new SwipeMenuAdapter(getContext(), adapter) {
@Override
public void createMenu(SwipeMenu menu) {
if (mMenuCreator != null) {
mMenuCreator.create(menu);
}
}
@Override
public void onItemClick(SwipeMenuView view, SwipeMenu menu,
int index) {
boolean flag = false;
if (mOnMenuItemClickListener != null) {
flag = mOnMenuItemClickListener.onMenuItemClick(
view.getPosition(), menu, index);
}
if (mTouchView != null && !flag) {
mTouchView.smoothCloseMenu();
}
}
}
SwipeMenuAdapterのコードに入って見て
@Override
public View getView(int position, View convertView, ViewGroup parent) {
SwipeMenuLayout layout = null;
if (convertView == null) {
View contentView = mAdapter.getView(position, convertView, parent);
SwipeMenu menu = new SwipeMenu(mContext);
menu.setViewType(getItemViewType(position));
createMenu(menu);
SwipeMenuView menuView = new SwipeMenuView(menu,
(SwipeMenuListView) parent);
menuView.setOnSwipeItemClickListener(this);
SwipeMenuListView listView = (SwipeMenuListView) parent;
layout = new SwipeMenuLayout(contentView, menuView,
listView.getCloseInterpolator(),
listView.getOpenInterpolator());
layout.setPosition(position);
} else {
layout = (SwipeMenuLayout) convertView;
layout.closeMenu();
layout.setPosition(position);
View view = mAdapter.getView(position, layout.getContentView(),
parent);
}
bindView(layout,position);// ( )
if (mAdapter instanceof BaseSwipListAdapter) {
boolean swipEnable = (((BaseSwipListAdapter) mAdapter).getSwipEnableByPosition(position));
layout.setSwipEnable(swipEnable);
}
return layout;
}
SwipeMenuAdapter内部に戻ってbindViewメソッドを実装
//datas menu
@Override
public void bindView(SwipeMenuLayout layout, int position) {
if (datas != null && datas.size() > 0){
SwipeMenuView swipeMenuView = (SwipeMenuView) layout.getChildAt(1);
ViewGroup group = (ViewGroup) swipeMenuView.getChildAt(0);
TextView text = (TextView) group.getChildAt(0);
if (datas.get(position)){
text.setText(" ");
} else {
text.setText(" ");
}
}
}
データソースが変わった