本文整理了Java中android.support.v7.widget.helper.ItemTouchHelper.attachToRecyclerView()
方法的一些代码示例,展示了ItemTouchHelper.attachToRecyclerView()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ItemTouchHelper.attachToRecyclerView()
方法的具体详情如下:
包路径:android.support.v7.widget.helper.ItemTouchHelper
类名称:ItemTouchHelper
方法名:attachToRecyclerView
暂无
代码示例来源:origin: mcxtzhang/ZLayoutManager
@Override
public void onClick(View v) {
//mRv.setLayoutManager(new OverLayCardLayoutManager();
itemTouchHelper.attachToRecyclerView(mRv);
}
});
代码示例来源:origin: mcxtzhang/ZLayoutManager
@Override
public void onClick(View v) {
mRv.setLayoutManager(new FlowLayoutManager());//自己写的流式布局
itemTouchHelper.attachToRecyclerView(null);
}
});
代码示例来源:origin: hidroh/materialistic
@Override
public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
super.onDetachedFromRecyclerView(recyclerView);
mItemTouchHelper.attachToRecyclerView(null);
}
代码示例来源:origin: hidroh/materialistic
@Override
public void onAttachedToRecyclerView(final RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
mItemTouchHelper.attachToRecyclerView(recyclerView);
}
代码示例来源:origin: EverythingMe/overscroll-decor
protected void setUpTouchHelperCallback(final ItemTouchHelper.Callback itemTouchHelperCallback) {
new ItemTouchHelper(new ItemTouchHelperCallbackWrapper(itemTouchHelperCallback) {
@Override
public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
mIsItemTouchInEffect = actionState != 0;
super.onSelectedChanged(viewHolder, actionState);
}
}).attachToRecyclerView(mRecyclerView);
}
代码示例来源:origin: hidroh/materialistic
@Override
public void detach(Context context, RecyclerView recyclerView) {
super.detach(context, recyclerView);
recyclerView.removeOnScrollListener(mScrollListener);
mColors.recycle();
mItemTouchHelper.attachToRecyclerView(null);
}
代码示例来源:origin: TeamNewPipe/NewPipe
@Override
public void onViewCreated(@NonNull View rootView, @Nullable Bundle savedInstanceState) {
super.onViewCreated(rootView, savedInstanceState);
initButton(rootView);
RecyclerView listSelectedTabs = rootView.findViewById(R.id.selectedTabs);
listSelectedTabs.setLayoutManager(new LinearLayoutManager(requireContext()));
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(getItemTouchCallback());
itemTouchHelper.attachToRecyclerView(listSelectedTabs);
selectedTabsAdapter = new SelectedTabsAdapter(requireContext(), itemTouchHelper);
listSelectedTabs.setAdapter(selectedTabsAdapter);
}
代码示例来源:origin: north2016/T-MVP
@Override
public void initView() {
adapter = new RecyclerListAdapter();
mViewBinding.recyclerview.setHasFixedSize(true);
mViewBinding.recyclerview.setAdapter(adapter);
mItemTouchHelper = new ItemTouchHelper(new SimpleItemTouchHelperCallback());
mItemTouchHelper.attachToRecyclerView(mViewBinding.recyclerview);
}
代码示例来源:origin: hidroh/materialistic
@Override
public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
super.onDetachedFromRecyclerView(recyclerView);
MaterialisticDatabase.getInstance(recyclerView.getContext()).getLiveData().removeObserver(mObserver);
mItemTouchHelper.attachToRecyclerView(null);
mPrefObservable.unsubscribe(recyclerView.getContext());
}
代码示例来源:origin: jaydenxiao2016/AndroidFire
@Override
public void returnMineNewsChannels(List<NewsChannelTable> newsChannelsMine) {
channelAdapterMine = new ChannelAdapter(mContext,R.layout.item_news_channel);
newsChannelMineRv.setLayoutManager(new GridLayoutManager(this, 4, LinearLayoutManager.VERTICAL, false));
newsChannelMineRv.setItemAnimator(new DefaultItemAnimator());
newsChannelMineRv.setAdapter(channelAdapterMine);
channelAdapterMine.replaceAll(newsChannelsMine);
channelAdapterMine.setOnItemClickListener(new ChannelAdapter.OnItemClickListener() {
@Override
public void onItemClick(View view, int position) {
NewsChannelTable newsChannel = channelAdapterMine.get(position);
channelAdapterMore.add(newsChannel);
channelAdapterMine.removeAt(position);
mPresenter.onItemAddOrRemove((ArrayList<NewsChannelTable>) channelAdapterMine.getAll(), (ArrayList<NewsChannelTable>)channelAdapterMore.getAll());
}
});
ItemDragHelperCallback itemDragHelperCallback = new ItemDragHelperCallback(channelAdapterMine);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemDragHelperCallback);
itemTouchHelper.attachToRecyclerView(newsChannelMineRv);
channelAdapterMine.setItemDragHelperCallback(itemDragHelperCallback);
}
代码示例来源:origin: TeamNewPipe/NewPipe
private void buildQueue() {
itemsList.setAdapter(playQueueAdapter);
itemsList.setClickable(true);
itemsList.setLongClickable(true);
itemsList.clearOnScrollListeners();
itemsList.addOnScrollListener(getQueueScrollListener());
itemTouchHelper = new ItemTouchHelper(getItemTouchCallback());
itemTouchHelper.attachToRecyclerView(itemsList);
playQueueAdapter.setSelectedListener(getOnSelectedListener());
itemsListCloseButton.setOnClickListener(view -> onQueueClosed());
}
代码示例来源:origin: iMeiji/Toutiao
private void initData() {
final List<NewsChannelBean> enableItems = dao.query(Constant.NEWS_CHANNEL_ENABLE);
final List<NewsChannelBean> disableItems = dao.query(Constant.NEWS_CHANNEL_DISABLE);
GridLayoutManager manager = new GridLayoutManager(this, 4);
recyclerView.setLayoutManager(manager);
ItemDragHelperCallback callback = new ItemDragHelperCallback();
final ItemTouchHelper helper = new ItemTouchHelper(callback);
helper.attachToRecyclerView(recyclerView);
adapter = new NewsChannelAdapter(this, helper, enableItems, disableItems);
manager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {
@Override
public int getSpanSize(int position) {
int viewType = adapter.getItemViewType(position);
return viewType == NewsChannelAdapter.TYPE_MY || viewType == NewsChannelAdapter.TYPE_OTHER ? 1 : 4;
}
});
recyclerView.setAdapter(adapter);
adapter.setOnMyChannelItemClickListener((v, position) -> Toast.makeText(NewsChannelActivity.this, enableItems.get(position).getChannelName() + position, Toast.LENGTH_SHORT).show());
}
代码示例来源:origin: TeamNewPipe/NewPipe
private void unbind() {
if(serviceBound) {
unbindService(serviceConnection);
serviceBound = false;
stopPlayerListener();
if (player != null && player.getPlayQueueAdapter() != null) {
player.getPlayQueueAdapter().unsetSelectedListener();
}
if (itemsList != null) itemsList.setAdapter(null);
if (itemTouchHelper != null) itemTouchHelper.attachToRecyclerView(null);
itemsList = null;
itemTouchHelper = null;
player = null;
}
}
代码示例来源:origin: TeamNewPipe/NewPipe
private void buildQueue() {
itemsList = findViewById(R.id.play_queue);
itemsList.setLayoutManager(new LinearLayoutManager(this));
itemsList.setAdapter(player.getPlayQueueAdapter());
itemsList.setClickable(true);
itemsList.setLongClickable(true);
itemsList.clearOnScrollListeners();
itemsList.addOnScrollListener(getQueueScrollListener());
itemTouchHelper = new ItemTouchHelper(getItemTouchCallback());
itemTouchHelper.attachToRecyclerView(itemsList);
player.getPlayQueueAdapter().setSelectedListener(getOnSelectedListener());
}
代码示例来源:origin: google/ExoPlayer
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Getting the cast context later than onStart can cause device discovery not to take place.
try {
castContext = CastContext.getSharedInstance(this);
} catch (RuntimeException e) {
Throwable cause = e.getCause();
while (cause != null) {
if (cause instanceof DynamiteModule.LoadingException) {
setContentView(R.layout.cast_context_error_message_layout);
return;
}
cause = cause.getCause();
}
// Unknown error. We propagate it.
throw e;
}
setContentView(R.layout.main_activity);
localPlayerView = findViewById(R.id.local_player_view);
localPlayerView.requestFocus();
castControlView = findViewById(R.id.cast_control_view);
mediaQueueList = findViewById(R.id.sample_list);
ItemTouchHelper helper = new ItemTouchHelper(new RecyclerViewCallback());
helper.attachToRecyclerView(mediaQueueList);
mediaQueueList.setLayoutManager(new LinearLayoutManager(this));
mediaQueueList.setHasFixedSize(true);
mediaQueueListAdapter = new MediaQueueListAdapter();
findViewById(R.id.add_sample_button).setOnClickListener(this);
}
代码示例来源:origin: hidroh/materialistic
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
MaterialisticDatabase.getInstance(recyclerView.getContext()).getLiveData().observeForever(mObserver);
mItemTouchHelper.attachToRecyclerView(recyclerView);
toggleAutoMarkAsViewed(recyclerView);
mPrefObservable.subscribe(recyclerView.getContext(),
(key, contextChanged) -> {
mCallback.setSwipePreferences(recyclerView.getContext(),
Preferences.getListSwipePreferences(recyclerView.getContext()));
notifyDataSetChanged();
},
R.string.pref_list_swipe_left,
R.string.pref_list_swipe_right);
}
代码示例来源:origin: TeamNewPipe/NewPipe
@Override
protected void initListeners() {
super.initListeners();
headerTitleView.setOnClickListener(view -> createRenameDialog());
itemTouchHelper = new ItemTouchHelper(getItemTouchCallback());
itemTouchHelper.attachToRecyclerView(itemsList);
itemListAdapter.setSelectedListener(new OnClickGesture<LocalItem>() {
@Override
public void selected(LocalItem selectedItem) {
if (selectedItem instanceof PlaylistStreamEntry) {
final PlaylistStreamEntry item = (PlaylistStreamEntry) selectedItem;
NavigationHelper.openVideoDetailFragment(getFragmentManager(),
item.serviceId, item.url, item.title);
}
}
@Override
public void held(LocalItem selectedItem) {
if (selectedItem instanceof PlaylistStreamEntry) {
showStreamItemDialog((PlaylistStreamEntry) selectedItem);
}
}
@Override
public void drag(LocalItem selectedItem, RecyclerView.ViewHolder viewHolder) {
if (itemTouchHelper != null) itemTouchHelper.startDrag(viewHolder);
}
});
}
代码示例来源:origin: mcxtzhang/ZLayoutManager
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_swipe_card);
mRv = (RecyclerView) findViewById(R.id.rv);
mRv.setLayoutManager(new OverLayCardLayoutManager());
mRv.setAdapter(mAdapter = new CommonAdapter<SwipeCardBean>(this, mDatas = SwipeCardBean.initDatas(), R.layout.item_swipe_card) {
public static final String TAG = "zxt/Adapter";
@Override
public void convert(ViewHolder viewHolder, SwipeCardBean swipeCardBean) {
Log.d(TAG, "convert() called with: viewHolder = [" + viewHolder + "], swipeCardBean = [" + swipeCardBean + "]");
viewHolder.setText(R.id.tvName, swipeCardBean.getName());
viewHolder.setText(R.id.tvPrecent, swipeCardBean.getPostition() + " /" + mDatas.size());
Picasso.with(SwipeCardActivity.this).load(swipeCardBean.getUrl()).into((ImageView) viewHolder.getView(R.id.iv));
}
});
//初始化配置
CardConfig.initConfig(this);
ItemTouchHelper.Callback callback = new RenRenCallback(mRv, mAdapter, mDatas);
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(mRv);
findViewById(R.id.btnRefresh).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mDatas.add(new SwipeCardBean(100, "http://news.k618.cn/tech/201604/W020160407281077548026.jpg", "增加的"));
mAdapter.notifyDataSetChanged();
}
});
}
代码示例来源:origin: Rukey7/MvpApp
/**
* 启动拖拽和滑动
* @param view 视图
* @param adapter 适配器
*/
public static void startDragAndSwipe(RecyclerView view, BaseQuickAdapter adapter) {
SimpleItemTouchHelperCallback callback = new SimpleItemTouchHelperCallback(adapter);
final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback);
itemTouchHelper.attachToRecyclerView(view);
adapter.setDragStartListener(new OnStartDragListener() {
@Override
public void onStartDrag(RecyclerView.ViewHolder viewHolder) {
itemTouchHelper.startDrag(viewHolder);
}
});
adapter.setDragCallback(callback);
adapter.setDragColor(Color.LTGRAY);
}
代码示例来源:origin: liaoinstan/SpringView
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo8);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
initData();
springView = findViewById(R.id.springview);
springView.setType(SpringView.Type.FOLLOW);
springView.setListener(new SpringView.OnFreshListener() {
@Override
public void onRefresh() {
new Handler().postDelayed(() -> springView.onFinishFreshAndLoad(), 1000);
}
@Override
public void onLoadmore() {
new Handler().postDelayed(() -> springView.onFinishFreshAndLoad(), 1000);
}
});
springView.setHeader(new DefaultHeader(this));
springView.setFooter(new DefaultFooter(this));
RecyclerView recyclerView = findViewById(R.id.recycle);
recyclerView.setHasFixedSize(true);
RecyclerAdapter recyclerAdapter = new RecyclerAdapter(R.layout.item, mDatas);
recyclerView.setAdapter(recyclerAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
final ItemTouchHelper itemTouchHelper = new ItemTouchHelper(new MyItemTouchCallback(recyclerAdapter));
itemTouchHelper.attachToRecyclerView(recyclerView);
}
内容来源于网络,如有侵权,请联系作者删除!