我正在使用android-swipe-to-dismiss-undo进行滑动以删除gmail效果。
setOnItemClickListener 对我不起作用。这是因为我在我的适配器中使用 OnLongClickListener 和 setOnCheckedChangeListener ?
实施轻扫以解雇:
final SwipeToDismissTouchListener<ListViewAdapter> touchListener =
new SwipeToDismissTouchListener<>(
new ListViewAdapter(listItems),
new SwipeToDismissTouchListener.DismissCallbacks<ListViewAdapter>() {
@Override
public boolean canDismiss(int position) {
return true;
}
@Override
public void onDismiss(ListViewAdapter view, int position) {
// here I delete my item. This works perfectly.
}
});
listItems.setOnTouchListener(touchListener);
listItems.setOnScrollListener((AbsListView.OnScrollListener) touchListener.makeScrollListener());
listItems.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (touchListener.existPendingDismisses()) {
touchListener.undoPendingDismiss();
Toast.show(MyFragment.this, "x"); // toast never appears
} else {
Toast.show(MyFragment.this, "y"); // toast never appears
}
}
});
我的适配器:
public class ShoppingItemsCheckListAdapter extends BaseAdapter {
public interface OnCheckItemListener {
public void onCheckItem(ShoppingItem item, boolean isCheck);}
private List<ShoppingItem> shoppingItemsList = new ArrayList<ShoppingItem>();
public OnCheckItemListener onCheckItemListener;
private OnItemShoppingListLongListener onItemShoppingListLongListener = null;
public interface OnItemShoppingListLongListener {
public void onEditItem(ShoppingItem item);}
public ShoppingItemsCheckListAdapter(OnItemShoppingListLongListener onItemShoppingListLongListener, OnCheckItemListener onCheckItemListener) {
this.onCheckItemListener = onCheckItemListener;
this.onItemShoppingListLongListener = onItemShoppingListLongListener;}
public void setModel(List<ShoppingItem> shoppingItemsList) {
this.shoppingItemsList = shoppingItemsList;
notifyDataSetChanged();}
@Override
public int getCount() {return shoppingItemsList.size();}
@Override
public Object getItem(int position) {return shoppingItemsList.get(position);}
@Override
public long getItemId(int position) {return position;}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_item_shopping_item, parent, false);
final ShoppingItem item = shoppingItemsList.get(position);
CheckBox checkBox = (CheckBox) convertView.findViewById(R.id.list_item_shopping_item_check);
checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
onCheckItemListener.onCheckItem(item, isChecked);
}
});
checkBox.setChecked(item.getCheck());
checkBox.setText(item.getLabel());
checkBox.setOnLongClickListener(new OnClickEditItemListener(item));
return convertView;
}
private class OnClickEditItemListener implements View.OnLongClickListener {
private ShoppingItem item;
public OnClickEditItemListener(ShoppingItem item) {
this.item = item;
}
@Override
public boolean onLongClick(View v) {
if (onItemShoppingListLongListener != null) {
onItemShoppingListLongListener.onEditItem(item);
}
return true;
}}}
有没有办法一起使用OnItemClickListener,OnLongClickListener和OnCheckedChangeListener?