I am trying to temporary disable onLongPressListener that I set in my adapter's ViewHolder. I want to disable it because I want to implement the Drag and Drop functionality (to allow the user to rearrange the items) of the RecyclerView.
Currently, the long press listener allows the user to rename an item and I want when the user presses the "rearrange" button (in the toolbar) I want to disable the viewHolder's long press listener and activate the drag and drop feature.I have no idea how I have to disable the listener which is set on every view of the recyclerview.
This is my adapter code:
public class GroceryItemsAdapter extends RecyclerView.Adapter<GroceryItemsAdapter.ShoppingListViewHolder> {
private ArrayList<String> mItems;
private Context mContext;
private SharedPreferences mSharedPreferences;
private SharedPreferences.Editor mEditor;
private MaterialDialog addItemdialog;
public static String nameOfList;
public GroceryItemsAdapter(Context context, ArrayList<String> items, SharedPreferences preferences, SharedPreferences.Editor editor, String nameOfList) {
mItems = items;
mContext = context;
mSharedPreferences = preferences;
mEditor = editor;
this.nameOfList = nameOfList;
}
@Override
public ShoppingListViewHolder onCreateViewHolder(ViewGroup viewGroup, int position) {
View view = LayoutInflater.from(mContext).inflate(R.layout.shopping_list_item,viewGroup,false);
ShoppingListViewHolder viewHolder = new ShoppingListViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(ShoppingListViewHolder shoppingListViewHolder, int position) {
shoppingListViewHolder.bindShoppingList(mItems.get(position));
}
@Override
public int getItemCount() {
return mItems.size();
}
public class ShoppingListViewHolder extends RecyclerView.ViewHolder implements CompoundButton.OnCheckedChangeListener, View.OnLongClickListener{
public TextView mShoppingListItem;
public CheckBox mCheckBox;
public TextView mEmptyTextView;
public ShoppingListViewHolder(View itemView) {
super(itemView);
mShoppingListItem = (TextView) itemView.findViewById(R.id.shoppingListItem);
mCheckBox = (CheckBox) itemView.findViewById(R.id.shoppingListCheckBox);
View rootView = ((Activity)mContext).getWindow().getDecorView().findViewById(android.R.id.content);
mEmptyTextView = (TextView)rootView.findViewById(R.id.list_empty);
mEmptyTextView.setVisibility(View.INVISIBLE);
mCheckBox.setOnCheckedChangeListener(this);
itemView.setOnLongClickListener(this);
}
public void bindShoppingList(String item){
mShoppingListItem.setText(item);
mCheckBox.setChecked(false);
}
}
}