diff --git a/app/src/main/java/com/luhuan/provider/Main2Activity.java b/app/src/main/java/com/luhuan/provider/Main2Activity.java index 3fe2ef6..8997521 100644 --- a/app/src/main/java/com/luhuan/provider/Main2Activity.java +++ b/app/src/main/java/com/luhuan/provider/Main2Activity.java @@ -46,13 +46,20 @@ protected void onCreate(Bundle savedInstanceState) { RxAdapter adapter=new RxAdapter(list,this) { @Override public RxViewHolder getHolder(ViewGroup parent) { - View view=View.inflate(Main2Activity.this,R.layout.item2_adpter,parent); + View view=View.inflate(Main2Activity.this,R.layout.item2_adpter,null); return new ViewHoder(view); } }; recyclerView.addItemDecoration(itemDec); recyclerView.setAdapter(adapter); RecyclerPagerHelper.getIntance().getPosition(recyclerView,null); + adapter.setOnItemClickListener(new RxAdapter.OnItemClickLitener() { + @Override + public void onItemClick(int position, Integer integer) { + RxToast.show(position+""); + } + }); + } private class ItemDec extends RecyclerView.ItemDecoration{ diff --git a/rxprovider/src/main/java/com/luhuan/rxprovider/customview/recycler/RxAdapter.java b/rxprovider/src/main/java/com/luhuan/rxprovider/customview/recycler/RxAdapter.java index 50f3113..8ddd104 100644 --- a/rxprovider/src/main/java/com/luhuan/rxprovider/customview/recycler/RxAdapter.java +++ b/rxprovider/src/main/java/com/luhuan/rxprovider/customview/recycler/RxAdapter.java @@ -11,6 +11,7 @@ import io.reactivex.annotations.NonNull; import io.reactivex.functions.Consumer; +import io.reactivex.functions.Predicate; /** * Created by luhuan on 2017/3/21. @@ -47,14 +48,16 @@ public RxViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { public void onBindViewHolder(RxViewHolder holder, final int position) { holder.setData(list.get(position)); RxListener.click(holder.itemView) + .filter(new Predicate() { + @Override + public boolean test(@NonNull Object o) throws Exception { + return onItemClickListener != null; + } + }) .subscribe(new Consumer() { @Override public void accept(@NonNull Object o) throws Exception { - if (onItemClickListener == null) { - Log.d(TAG, "OnItemClickLitener==null,您没有设置监听"); - } else { - onItemClickListener.onItemClick(position, list.get(position)); - } + onItemClickListener.onItemClick(position, list.get(position)); } }); }