防止点击事件导航回Recyclerview android

时间:2016-12-18 10:03:13

标签: android android-recyclerview floating-action-button

我有一个recyclerview,其中包含imageviewtextviewfloating action button我已附加addOnItemTouchListener事件以导航到fullscreen view }。除此之外,click event内的floating action button附加了recyclerview

recyclerView.addOnItemTouchListener(new GalleryAdapter.RecyclerTouchListener(getApplicationContext(), recyclerView, new GalleryAdapter.ClickListener() {
    @Override
    public void onClick(View view, int position) {
        FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
        SlideshowDialogFragment newFragment = SlideshowDialogFragment.newInstance();
        newFragment.show(ft, "slideshow");
    }
    @Override
    public void onLongClick(View view, int position) {

    }
}));

以下是FAB内的RecyclerView

<android.support.design.widget.FloatingActionButton
        android:id="@+id/select_cake"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:clickable="true"
        android:descendantFocusability="blocksDescendants"
        app:fabSize="normal"
        app:layout_anchorGravity="top|right|end" />
</android.support.design.widget.CoordinatorLayout>
clickevent

GalleryAdapter

view.findViewById(R.id.select_cake).setOnClickListener(new View.OnClickListener() {
     @Override
     public void onClick(View view) {
          Toast.makeText(mContext,"Test Toast",Toast.LENGTH_LONG).show();
     }
});

但是,每当我点击FAB时,就会显示toast,但它也会通过recyclerView's ItemTouchListner

导航到其他视图

我已将android:descendantFocusability="blocksDescendants"android:clickable="true"用于FAB,但该事件仍会导航到其父recyclerView,从而为recyclerItemClick执行代码行}。我该如何防止这种行为?

0 个答案:

没有答案