RecyclerView-Animation wurde nicht getestet, das andere ist normal. Ich denke, es wurde maximal optimiert. Das Interface hat andere Verwendungen, die vorübergehend ignoriert werden können.
public abstract class BaseAdapterRV extends RecyclerView.Adapter implements AdapterInterface {
public final String TAG = getClass().getSimpleName();
protected final Activity mActivity;
protected final LayoutInflater mInflater;
protected ItemClickInterface mListener;
public BaseAdapterRV(Activity activity) {
mActivity = activity;
mInflater = LayoutInflater.from(mActivity);
}
@Override
public final VH onCreateViewHolder(ViewGroup parent, int viewType) {
return onCreateViewHolder(parent, viewType, mInflater);
}
@Override
public final void onBindViewHolder(VH holder, int position) {
holder.itemView.setTag(R.id.tag_view_click, position);
//
holder.itemView.setOnClickListener(mListener);
holder.itemView.setOnLongClickListener(mListener);
onBindVH(holder, position);
}
///////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////
/**
* !notifyItemInsertedposition
* onItemLongClick
*/
public void setOnItemClickListener(ItemClickInterface listener) {
mListener = listener;
notifyDataSetChanged();
}
@NonNull
protected abstract VH onCreateViewHolder(ViewGroup parent, int viewType, LayoutInflater inflater);
protected abstract void onBindVH(VH holder, int position);
}
Dies ist ein Interface
/**
* OnItemClickListener
* {@link OnItemClickListener}{@link OnItemItemClickListener}
*/
public interface ItemClickInterface extends View.OnClickListener, View.OnLongClickListener {
void onItemClick(DATA1 data1, DATA2 data2);
boolean onItemLongClick(DATA1 data1, DATA2 data2);
}
Dies ist eine abstrakte Klasse
public abstract class OnItemClickListener implements ItemClickInterface {
@Override
public void onClick(View v) {
onItemClick(v, (DATA) v.getTag(R.id.tag_view_click));
}
@Override
public boolean onLongClick(View v) {
return onItemLongClick(v, (DATA) v.getTag(R.id.tag_view_click));
}
@Override
public boolean onItemLongClick(View view, DATA data) {
return false;
}
}
Sie benötigen nur das Folgende
mAdapter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(View view, Integer integer) {
}
@Override
public boolean onItemLongClick(View view, Integer integer) {
return true;
}
});