Java Code Examples for androidx.recyclerview.widget.RecyclerView#addOnItemTouchListener()

The following examples show how to use androidx.recyclerview.widget.RecyclerView#addOnItemTouchListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GalleryFragment.java    From animation-samples with Apache License 2.0 6 votes vote down vote up
private void initRecyclerView(View contentView) {
    mRecyclerView = (RecyclerView) contentView.findViewById(R.id.galleries);
    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.addOnItemTouchListener(
            new RecyclerItemClickListener(getActivity()) {
                @Override
                public void onItemClick(RecyclerView.ViewHolder holder, int position) {
                    showDetailFragment((GalleryViewHolder) holder,
                            mGalleries.get(position));
                }
            });
    final int itemMargin = getResources().getDimensionPixelSize(R.dimen.grid_single);
    mRecyclerView.addItemDecoration(new GalleryDivider(itemMargin));
}
 
Example 2
Source File: RecyclerViewFragment.java    From android-test with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
    Bundle savedInstanceState) {
  final LayoutManagerType layoutManagerType = (LayoutManagerType) getArguments()
      .getSerializable(KEY_EXTRA_LAYOUT_MANAGER_TYPE);

  final View view = inflater
      .inflate(layoutManagerType.getLayoutId(), container, false);

  selectedItemView = (TextView) view.findViewById(layoutManagerType.getSelectedItemId());
  recyclerView = (RecyclerView) view.findViewById(layoutManagerType.getRVId());
  recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(),
      DividerItemDecoration.VERTICAL_LIST));
  recyclerView.setHasFixedSize(true);
  recyclerView.addOnItemTouchListener(this);
  gestureDetector = new GestureDetectorCompat(getActivity(), new ItemTouchGestureDetector());
  layoutManager = getLayoutManager(layoutManagerType);
  recyclerView.setLayoutManager(layoutManager);

  // Specify an adapter which displays items
  List<String> items = makeItems();
  adapter = ItemListAdapter.newItemListAdapter(items, inflater);
  recyclerView.setAdapter(adapter);
  return view;
}
 
Example 3
Source File: DrawerHelper.java    From UIWidget with Apache License 2.0 5 votes vote down vote up
public void initRecyclerView(final Activity mContext, RecyclerView mRecyclerViewDrawer, List<DrawerEntity> list) {
    final BaseQuickAdapter mAdapterDrawer = new DrawerAdapter(mContext);
    mRecyclerViewDrawer.setLayoutManager(new LinearLayoutManager(mContext));
    mRecyclerViewDrawer.setAdapter(mAdapterDrawer);
    mRecyclerViewDrawer.addOnItemTouchListener(new OnItemClickListener() {
        @Override
        public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
            DrawerEntity entity = (DrawerEntity) mAdapterDrawer.getItem(position);
            WebViewActivity.start(mContext,entity.url);
        }
    });
    mAdapterDrawer.setNewData(list);
}
 
Example 4
Source File: StickyHeaderFragment.java    From header-decor with Apache License 2.0 5 votes vote down vote up
@Override
protected void setAdapterAndDecor(@NonNull RecyclerView list) {
    final StickyTestAdapter adapter = new StickyTestAdapter(requireContext());
    decor = new StickyHeaderDecoration(adapter);
    setHasOptionsMenu(true);

    list.setAdapter(adapter);
    list.addItemDecoration(decor, 1);
    list.addOnItemTouchListener(this);
}
 
Example 5
Source File: InlineDoubleHeaderFragment.java    From header-decor with Apache License 2.0 5 votes vote down vote up
@Override
protected void setAdapterAndDecor(@NonNull RecyclerView list) {
    final InlineDoubleHeaderTestAdapter adapter = new InlineDoubleHeaderTestAdapter(requireContext());
    decor = new DoubleHeaderDecoration(adapter, true);
    setHasOptionsMenu(true);

    list.setAdapter(adapter);
    list.addItemDecoration(decor, 1);
    list.addOnItemTouchListener(this);
}
 
Example 6
Source File: DoubleHeaderFragment.java    From header-decor with Apache License 2.0 5 votes vote down vote up
@Override
protected void setAdapterAndDecor(@NonNull RecyclerView recyclerView) {
    final DoubleHeaderTestAdapter adapter = new DoubleHeaderTestAdapter(requireContext());
    decor = new DoubleHeaderDecoration(adapter);
    setHasOptionsMenu(true);

    recyclerView.setAdapter(adapter);
    recyclerView.addItemDecoration(decor, 1);
    recyclerView.addOnItemTouchListener(this);
}
 
Example 7
Source File: ConversationItemSwipeCallback.java    From mollyim-android with GNU General Public License v3.0 4 votes vote down vote up
void attachToRecyclerView(@NonNull RecyclerView recyclerView) {
  recyclerView.addOnItemTouchListener(itemTouchListener);
  new ItemTouchHelper(this).attachToRecyclerView(recyclerView);
}
 
Example 8
Source File: ItemClickSupport.java    From MusicBobber with MIT License 4 votes vote down vote up
private ItemClickSupport(RecyclerView recyclerView) {
    mRecyclerView = recyclerView;

    mTouchListener = new TouchListener(recyclerView);
    recyclerView.addOnItemTouchListener(mTouchListener);
}