use of com.marshalchen.common.uimodule.twowayview.ItemClickSupport.OnItemLongClickListener in project UltimateAndroid by cymcsg.
the class LayoutFragment method onViewCreated.
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final Activity activity = getActivity();
mToast = Toast.makeText(activity, "", Toast.LENGTH_SHORT);
mToast.setGravity(Gravity.CENTER, 0, 0);
mRecyclerView = (TwoWayView) view.findViewById(R.id.list);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLongClickable(true);
mPositionText = (TextView) view.getRootView().findViewById(R.id.position);
mCountText = (TextView) view.getRootView().findViewById(R.id.count);
mStateText = (TextView) view.getRootView().findViewById(R.id.state);
updateState(SCROLL_STATE_IDLE);
final ItemClickSupport itemClick = ItemClickSupport.addTo(mRecyclerView);
itemClick.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(RecyclerView parent, View child, int position, long id) {
mToast.setText("Item clicked: " + position);
mToast.show();
}
});
itemClick.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(RecyclerView parent, View child, int position, long id) {
mToast.setText("Item long pressed: " + position);
mToast.show();
return true;
}
});
mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int scrollState) {
updateState(scrollState);
}
@Override
public void onScrolled(RecyclerView recyclerView, int i, int i2) {
mPositionText.setText("First: " + mRecyclerView.getFirstVisiblePosition());
mCountText.setText("Count: " + mRecyclerView.getChildCount());
}
});
final Drawable divider = getResources().getDrawable(R.drawable.two_way_view_divider);
mRecyclerView.addItemDecoration(new DividerItemDecoration(divider));
mRecyclerView.setAdapter(new LayoutAdapter(activity, mRecyclerView, mLayoutId));
}
Aggregations