1
This commit is contained in:
@@ -16,6 +16,8 @@ import android.widget.AdapterView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import entity.DiscoveryListEntity;
|
||||
|
||||
|
||||
public class BaseRecycleViewAdapter<T1, T2 extends ViewDataBinding> extends RecyclerView.Adapter<BaseRecycleViewAdapter.BaseViewHolder> {
|
||||
private ArrayList<T1> list;
|
||||
@@ -29,7 +31,6 @@ public class BaseRecycleViewAdapter<T1, T2 extends ViewDataBinding> extends Recy
|
||||
private static OnLongItemClickListener longItemClickListener;
|
||||
|
||||
|
||||
|
||||
public BaseRecycleViewAdapter(Context context, @LayoutRes int layout) {
|
||||
inflater = LayoutInflater.from(context);
|
||||
this.context = context;
|
||||
@@ -40,10 +41,11 @@ public class BaseRecycleViewAdapter<T1, T2 extends ViewDataBinding> extends Recy
|
||||
|
||||
public void setData(ArrayList<T1> list) {
|
||||
this.list.clear();
|
||||
this.list=new ArrayList<>();
|
||||
this.list = new ArrayList<>();
|
||||
this.list.addAll(list);
|
||||
notifyDataSetChanged();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void addData(ArrayList<T1> list) {
|
||||
this.list = list;
|
||||
this.list.addAll(list);
|
||||
@@ -51,6 +53,11 @@ public class BaseRecycleViewAdapter<T1, T2 extends ViewDataBinding> extends Recy
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void upDateOne(int position, T1 bean) {
|
||||
this.list.set(position, bean);
|
||||
notifyItemChanged(position);
|
||||
}
|
||||
|
||||
public void setOnBindViewHolder(BindView bindView) {
|
||||
this.bindView = bindView;
|
||||
}
|
||||
@@ -68,6 +75,11 @@ public class BaseRecycleViewAdapter<T1, T2 extends ViewDataBinding> extends Recy
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return list.size();
|
||||
@@ -76,15 +88,19 @@ public class BaseRecycleViewAdapter<T1, T2 extends ViewDataBinding> extends Recy
|
||||
public interface BindView<T2> {
|
||||
void onBindViewHolder(T2 b, int position);
|
||||
}
|
||||
|
||||
public interface OnItemClickListener {
|
||||
void onItemClick(View itemView, int position);
|
||||
}
|
||||
|
||||
public interface OnLongItemClickListener {
|
||||
void onItemLongClick(View itemView, int position);
|
||||
}
|
||||
|
||||
public void setOnItemLongClickListener(OnLongItemClickListener longClickListener) {
|
||||
this.longItemClickListener = longClickListener;
|
||||
}
|
||||
|
||||
public void setOnItemClickListener(OnItemClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
@@ -104,25 +120,26 @@ public class BaseRecycleViewAdapter<T1, T2 extends ViewDataBinding> extends Recy
|
||||
|
||||
});
|
||||
|
||||
itemView.setOnLongClickListener(new View.OnLongClickListener(){
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
itemView.setOnLongClickListener(new View.OnLongClickListener() {
|
||||
@Override
|
||||
public boolean onLongClick(View v) {
|
||||
|
||||
if (longItemClickListener != null)
|
||||
longItemClickListener.onItemLongClick(itemView,getLayoutPosition());
|
||||
return true;
|
||||
}
|
||||
if (longItemClickListener != null)
|
||||
longItemClickListener.onItemLongClick(itemView, getLayoutPosition());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public ViewDataBinding getBinding() {
|
||||
return b;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user