2 回答

TA贡献1864条经验 获得超6个赞
在您的适配器类中创建一个公共函数和一个私有变量
Int id;
public void setId(int id) {
this.id = id;
}
现在通过您的片段设置 ID
petchingLoungeAdapter = new PetchingLoungeAdapter(getContext(), userList);
petchingLoungeAdapter.setId(/* set ID here */) ;
recyclerView.setAdapter(petchingLoungeAdapter);

TA贡献1876条经验 获得超5个赞
你可以像这样编写适配器类的构造函数
Context mContext;
List<User> mUser;
String id;
public PetchingLoungeAdapter(Context mContext, List<User> mUser, String id)
{
this.mContext = mContext;
this.mUser = mUser;
this.id=id;
}
你可以从你的片段中调用这个构造函数,如下所示
petchingLoungeAdapter = new PetchingLoungeAdapter(getContext(), userList,id);// pass the id here ( ds.getKey() ).
recyclerView.setAdapter(petchingLoungeAdapter);
添加回答
举报