2 回答

TA貢獻1864條經(jīng)驗 獲得超6個贊
在您的適配器類中創(chuàng)建一個公共函數(shù)和一個私有變量
Int id;
public void setId(int id) {
this.id = id;
}
現(xiàn)在通過您的片段設(shè)置 ID
petchingLoungeAdapter = new PetchingLoungeAdapter(getContext(), userList);
petchingLoungeAdapter.setId(/* set ID here */) ;
recyclerView.setAdapter(petchingLoungeAdapter);

TA貢獻1876條經(jīng)驗 獲得超5個贊
你可以像這樣編寫適配器類的構(gòu)造函數(shù)
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;
}
你可以從你的片段中調(diào)用這個構(gòu)造函數(shù),如下所示
petchingLoungeAdapter = new PetchingLoungeAdapter(getContext(), userList,id);// pass the id here ( ds.getKey() ).
recyclerView.setAdapter(petchingLoungeAdapter);
添加回答
舉報