RecyclerView Adapter onBind方法 [英] RecyclerView Adapter onBind method
问题描述
我在MainActivity 3 RecyclerViews中.
其中一个是底部表单,它是主要表单(默认情况下,底部表单是Open To Display this),这是其 适配器的onbind方法 做了一个 onClickListener ,以便当用户单击该项目时我想要
One of them in a bottom sheet and it is the main one (By Default the Bottom sheet is Open To Display this one ), in its adapter's onbind method I made an onClickListener so that I want when the user clicks on an item in it,
我想返回到主活动类,以设置要开始滚动的方法,是要关闭底部工作表并为下一个回收视图设置数据(当底页已关闭)
I want to go back to the main activity class to set To Start a method which it's rolled is to close the Bottom Sheet and set the data for the next recycling view (which will appear when the Bottom Sheet is closed)
....这里的问题是如何从onBind方法的Listener启动此方法,并从此viewHolder中为其指定一个参数作为其名称和一些属性
..... The issue here is how to start this method from the onBind method's Listener and give it a parameter from this viewHolder as its name and some of its attributes
如果有不清楚的地方,请告诉我
if there is something not clear please let me know
@Override
public void onBindViewHolder(@NonNull final ViewHolder viewHolder, final int position) {
viewHolder.categoryImage.setImageResource(mRowOfCategories.get(position).getCategoryImage());
viewHolder.categoryName.setText(mRowOfCategories.get(position).getCategoryName());
viewHolder.mCardView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
}
});
}
推荐答案
最简单:
您在活动"中声明要调用的方法.它必须是公开的:
You declare the method you want to call in your Activity. It has to be public:
public void method(){}
然后,在适配器的构造函数中,将对Activity的引用作为参数传递:
Then, in the Constructor of the Adapter, you pass a reference to the Activity as a parameter:
public MyAdapter(Activity activity){}
而且,在onBindViewHolder中:
And, in the onBindViewHolder:
MyActivity mActivity=(MyActivity)activity;
mActivity.method();
这篇关于RecyclerView Adapter onBind方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!