Java 如何在片段抛出适配器中传递接口?
内部碎片Java 如何在片段抛出适配器中传递接口?,java,android,Java,Android,内部碎片 userListAdapter = new UserListAdapter(getActivity(), response.getTray(), ?); RVUserList.setAdapter(userListAdapter); 输入适配器 public UserListAdapter(Context context, ArrayList<TrayModel> list, UserListInterface listInterface)
userListAdapter = new UserListAdapter(getActivity(), response.getTray(), ?);
RVUserList.setAdapter(userListAdapter);
输入适配器
public UserListAdapter(Context context, ArrayList<TrayModel> list, UserListInterface listInterface) {
this.context = context;
this.trayModelArrayList = list;
this.userListInterface = listInterface;
}
公共UserListAdapter(上下文上下文、ArrayList列表、UserListInterface listInterface){
this.context=上下文;
this.traymodelarylist=list;
this.userListInterface=listInterface;
}
还可以在fragment中实现UserListInterface,而这个代码片段可以解决这个问题,真正有助于提高文章的质量。请记住,您将在将来回答读者的问题,这些人可能不知道您的代码建议的原因。
userListAdapter = new UserListAdapter(getActivity(), response.getTray(), new UserListInterface(){
// interface methods
});
RVUserList.setAdapter(userListAdapter);
userListAdapter = new UserListAdapter(getActivity(), response.getTray(), HomeFragment.this::userListClick);
RVUserList.setAdapter(userListAdapter);