FastAdapter Position

和自甴很熟 提交于 2019-12-06 15:01:22

You should not set click listeners within the ViewHolder as you would not be able to access position or anything. Please use the ClickListenerHelper as shown in the sample.

//init the ClickListenerHelper which simplifies custom click listeners on views of the Adapter
mClickListenerHelper = new ClickListenerHelper<>(fastItemAdapter);

fastItemAdapter.withOnCreateViewHolderListener(new FastAdapter.OnCreateViewHolderListener() {
    @Override
    public RecyclerView.ViewHolder onPreCreateViewHolder(ViewGroup parent, int viewType) {
        return fastItemAdapter.getTypeInstance(viewType).getViewHolder(parent);
    }

    @Override
    public RecyclerView.ViewHolder onPostCreateViewHolder(final RecyclerView.ViewHolder viewHolder) {
        mClickListenerHelper.listen(viewHolder, ((Doc_Appointment_Req_Adapter.Doc_App_req_Vh) viewHolder). accept, new ClickListenerHelper.OnClickListener<Doc_Appointment_Req_Adapter>() {
            @Override
            public void onClick(View v, int position, Doc_Appointment_Req_Adapter item) {
                ...
            }
        });
        return viewHolder;
    }
});

Basically, this will add a listener to the view when the ViewHolder is created. And returns the item, the position, and its view for you.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!