Search in sources :

Example 1 with OnItemClickListener

use of com.chad.library.adapter.base.listener.OnItemClickListener in project BaseRecyclerViewAdapterHelper by CymChad.

the class ItemClickActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setBackBtn();
    setTitle("ItemClickActivity Activity");
    setContentView(R.layout.activity_item_click);
    mRecyclerView = (RecyclerView) findViewById(R.id.list);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    initAdapter();
    mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {

        /**
             * Callback method to be invoked when an item in this AdapterView has
             * been clicked.
             *
             * @param view     The view within the AdapterView that was clicked (this
             *                 will be a view provided by the adapter)
             * @param position The position of the view in the adapter.
             */
        @Override
        public void onSimpleItemClick(final BaseQuickAdapter adapter, final View view, final int position) {
            Log.d(TAG, "SimpleOnItemClick: ");
            Toast.makeText(ItemClickActivity.this, "onSimpleItemClick" + position, Toast.LENGTH_SHORT).show();
        }

        /**
             * callback method to be invoked when an chidview in this view has been
             * click and held
             *
             * @param view     The view whihin the AbsListView that was clicked
             * @param position The position of the view int the adapter
             * @return true if the callback consumed the long click ,false otherwise
             */
        @Override
        public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
            Logger.d("onItemChildClick " + position + " be click");
            Toast.makeText(ItemClickActivity.this, "onItemChildClick" + position, Toast.LENGTH_SHORT).show();
        }

        /**
             * Callback method to be invoked when an item in this view has been clicked and held.
             * @param adapter
             * @param view
             * @param position
             */
        @Override
        public void onItemLongClick(final BaseQuickAdapter adapter, final View view, final int position) {
            Toast.makeText(ItemClickActivity.this, "onItemLongClick" + position, Toast.LENGTH_SHORT).show();
        }

        /**
             * Callback method to be invoked when an itemchild in this view has been clicked and held.
             * @param adapter
             * @param view
             * @param position
             */
        @Override
        public void onItemChildLongClick(final BaseQuickAdapter adapter, final View view, final int position) {
            Toast.makeText(ItemClickActivity.this, "onItemChildLongClick" + position, Toast.LENGTH_SHORT).show();
        }
    });
}
Also used : OnItemClickListener(com.chad.library.adapter.base.listener.OnItemClickListener) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 2 with OnItemClickListener

use of com.chad.library.adapter.base.listener.OnItemClickListener in project BaseRecyclerViewAdapterHelper by CymChad.

the class HomeActivity method initAdapter.

private void initAdapter() {
    BaseQuickAdapter homeAdapter = new HomeAdapter(R.layout.home_item_view, mDataList);
    homeAdapter.openLoadAnimation();
    View top = getLayoutInflater().inflate(R.layout.top_view, (ViewGroup) mRecyclerView.getParent(), false);
    homeAdapter.addHeaderView(top);
    mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {

        @Override
        public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
            Intent intent = new Intent(HomeActivity.this, ACTIVITY[position]);
            startActivity(intent);
        }
    });
    mRecyclerView.setAdapter(homeAdapter);
}
Also used : OnItemClickListener(com.chad.library.adapter.base.listener.OnItemClickListener) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) HomeAdapter(com.chad.baserecyclerviewadapterhelper.adapter.HomeAdapter) Intent(android.content.Intent) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 3 with OnItemClickListener

use of com.chad.library.adapter.base.listener.OnItemClickListener in project BaseRecyclerViewAdapterHelper by CymChad.

the class ItemDragAndSwipeUseActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_item_touch_use);
    setBackBtn();
    setTitle("ItemDrag  And Swipe");
    mRecyclerView = (RecyclerView) findViewById(R.id.rv_list);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mData = generateData(50);
    OnItemDragListener listener = new OnItemDragListener() {

        @Override
        public void onItemDragStart(RecyclerView.ViewHolder viewHolder, int pos) {
            Log.d(TAG, "drag start");
            BaseViewHolder holder = ((BaseViewHolder) viewHolder);
        //                holder.setTextColor(R.id.tv, Color.WHITE);
        }

        @Override
        public void onItemDragMoving(RecyclerView.ViewHolder source, int from, RecyclerView.ViewHolder target, int to) {
            Log.d(TAG, "move from: " + source.getAdapterPosition() + " to: " + target.getAdapterPosition());
        }

        @Override
        public void onItemDragEnd(RecyclerView.ViewHolder viewHolder, int pos) {
            Log.d(TAG, "drag end");
            BaseViewHolder holder = ((BaseViewHolder) viewHolder);
        //                holder.setTextColor(R.id.tv, Color.BLACK);
        }
    };
    final Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setTextSize(20);
    paint.setColor(Color.BLACK);
    OnItemSwipeListener onItemSwipeListener = new OnItemSwipeListener() {

        @Override
        public void onItemSwipeStart(RecyclerView.ViewHolder viewHolder, int pos) {
            Log.d(TAG, "view swiped start: " + pos);
            BaseViewHolder holder = ((BaseViewHolder) viewHolder);
        //                holder.setTextColor(R.id.tv, Color.WHITE);
        }

        @Override
        public void clearView(RecyclerView.ViewHolder viewHolder, int pos) {
            Log.d(TAG, "View reset: " + pos);
            BaseViewHolder holder = ((BaseViewHolder) viewHolder);
        //                holder.setTextColor(R.id.tv, Color.BLACK);
        }

        @Override
        public void onItemSwiped(RecyclerView.ViewHolder viewHolder, int pos) {
            Log.d(TAG, "View Swiped: " + pos);
        }

        @Override
        public void onItemSwipeMoving(Canvas canvas, RecyclerView.ViewHolder viewHolder, float dX, float dY, boolean isCurrentlyActive) {
            canvas.drawColor(ContextCompat.getColor(ItemDragAndSwipeUseActivity.this, R.color.color_light_blue));
        //                canvas.drawText("Just some text", 0, 40, paint);
        }
    };
    mAdapter = new ItemDragAdapter(mData);
    mItemDragAndSwipeCallback = new ItemDragAndSwipeCallback(mAdapter);
    mItemTouchHelper = new ItemTouchHelper(mItemDragAndSwipeCallback);
    mItemTouchHelper.attachToRecyclerView(mRecyclerView);
    //mItemDragAndSwipeCallback.setDragMoveFlags(ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT | ItemTouchHelper.UP | ItemTouchHelper.DOWN);
    mItemDragAndSwipeCallback.setSwipeMoveFlags(ItemTouchHelper.START | ItemTouchHelper.END);
    mAdapter.enableSwipeItem();
    mAdapter.setOnItemSwipeListener(onItemSwipeListener);
    mAdapter.enableDragItem(mItemTouchHelper);
    mAdapter.setOnItemDragListener(listener);
    //        mRecyclerView.addItemDecoration(new GridItemDecoration(this ,R.drawable.list_divider));
    mRecyclerView.setAdapter(mAdapter);
    mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {

        @Override
        public void onSimpleItemClick(final BaseQuickAdapter adapter, final View view, final int position) {
            ToastUtils.showShortToast("点击了" + position);
        }
    });
}
Also used : BaseViewHolder(com.chad.library.adapter.base.BaseViewHolder) OnItemClickListener(com.chad.library.adapter.base.listener.OnItemClickListener) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ItemDragAdapter(com.chad.baserecyclerviewadapterhelper.adapter.ItemDragAdapter) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Paint(android.graphics.Paint) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) BaseViewHolder(com.chad.library.adapter.base.BaseViewHolder) OnItemDragListener(com.chad.library.adapter.base.listener.OnItemDragListener) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) OnItemSwipeListener(com.chad.library.adapter.base.listener.OnItemSwipeListener) ItemDragAndSwipeCallback(com.chad.library.adapter.base.callback.ItemDragAndSwipeCallback)

Example 4 with OnItemClickListener

use of com.chad.library.adapter.base.listener.OnItemClickListener in project BaseRecyclerViewAdapterHelper by CymChad.

the class PullToRefreshUseActivity method initAdapter.

private void initAdapter() {
    pullToRefreshAdapter = new PullToRefreshAdapter();
    pullToRefreshAdapter.setOnLoadMoreListener(this, mRecyclerView);
    pullToRefreshAdapter.openLoadAnimation(BaseQuickAdapter.SLIDEIN_LEFT);
    //        pullToRefreshAdapter.setAutoLoadMoreSize(3);
    mRecyclerView.setAdapter(pullToRefreshAdapter);
    mCurrentCounter = pullToRefreshAdapter.getData().size();
    mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {

        @Override
        public void onSimpleItemClick(final BaseQuickAdapter adapter, final View view, final int position) {
            Toast.makeText(PullToRefreshUseActivity.this, Integer.toString(position), Toast.LENGTH_LONG).show();
        }
    });
}
Also used : OnItemClickListener(com.chad.library.adapter.base.listener.OnItemClickListener) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) PullToRefreshAdapter(com.chad.baserecyclerviewadapterhelper.adapter.PullToRefreshAdapter) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) CustomLoadMoreView(com.chad.baserecyclerviewadapterhelper.loadmore.CustomLoadMoreView) View(android.view.View)

Example 5 with OnItemClickListener

use of com.chad.library.adapter.base.listener.OnItemClickListener in project BaseRecyclerViewAdapterHelper by CymChad.

the class SectionUseActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_section_uer);
    setBackBtn();
    setTitle("Section Use");
    mRecyclerView = (RecyclerView) findViewById(R.id.rv_list);
    mRecyclerView.setLayoutManager(new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL));
    mData = DataServer.getSampleData();
    SectionAdapter sectionAdapter = new SectionAdapter(R.layout.item_section_content, R.layout.def_section_head, mData);
    mRecyclerView.addOnItemTouchListener(new OnItemClickListener() {

        @Override
        public void onSimpleItemClick(BaseQuickAdapter adapter, View view, int position) {
            MySection mySection = mData.get(position);
            if (mySection.isHeader)
                Toast.makeText(SectionUseActivity.this, mySection.header, Toast.LENGTH_LONG).show();
            else
                Toast.makeText(SectionUseActivity.this, mySection.t.getName(), Toast.LENGTH_LONG).show();
        }

        @Override
        public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
            Toast.makeText(SectionUseActivity.this, "onItemChildClick" + position, Toast.LENGTH_LONG).show();
        }
    });
    mRecyclerView.setAdapter(sectionAdapter);
}
Also used : MySection(com.chad.baserecyclerviewadapterhelper.entity.MySection) OnItemClickListener(com.chad.library.adapter.base.listener.OnItemClickListener) SectionAdapter(com.chad.baserecyclerviewadapterhelper.adapter.SectionAdapter) BaseQuickAdapter(com.chad.library.adapter.base.BaseQuickAdapter) StaggeredGridLayoutManager(android.support.v7.widget.StaggeredGridLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)6 View (android.view.View)6 BaseQuickAdapter (com.chad.library.adapter.base.BaseQuickAdapter)6 OnItemClickListener (com.chad.library.adapter.base.listener.OnItemClickListener)6 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 Intent (android.content.Intent)1 Canvas (android.graphics.Canvas)1 Paint (android.graphics.Paint)1 StaggeredGridLayoutManager (android.support.v7.widget.StaggeredGridLayoutManager)1 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 HeaderAndFooterAdapter (com.chad.baserecyclerviewadapterhelper.adapter.HeaderAndFooterAdapter)1 HomeAdapter (com.chad.baserecyclerviewadapterhelper.adapter.HomeAdapter)1 ItemDragAdapter (com.chad.baserecyclerviewadapterhelper.adapter.ItemDragAdapter)1 PullToRefreshAdapter (com.chad.baserecyclerviewadapterhelper.adapter.PullToRefreshAdapter)1 SectionAdapter (com.chad.baserecyclerviewadapterhelper.adapter.SectionAdapter)1 MySection (com.chad.baserecyclerviewadapterhelper.entity.MySection)1 CustomLoadMoreView (com.chad.baserecyclerviewadapterhelper.loadmore.CustomLoadMoreView)1 BaseViewHolder (com.chad.library.adapter.base.BaseViewHolder)1