gpt4 book ai didi

android - Recycularview 适配器未在 MVP 模式的选项卡 fragment 中设置,显示错误没有附加适配器跳过布局

转载 作者:行者123 更新时间:2023-11-30 05:10:52 25 4
gpt4 key购买 nike

I am using MVP pattern to display employee list using tablayout in recycular view i got error no adapter set code paste below, when i add the list value and recycular adapter inside return view means it works fine but if i goes separate interface method mean adapter not called

  <p></p>

public class Employees extends Fragment implements GeneralView {

View view;
private EmployeePresenter employeePresenter;
Response<ArrayPOJO> response;
public RecyclerView recyclerView;
public ArrayList<EmployeePojo> employeetList = new ArrayList<>();
public EmployeeAdapter empAdapter;
public EmployeePojo employeePojo;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

view = inflater.inflate(R.layout.fragment_employee, container, false);

Employees employees = new Employees();
employeePresenter = new EmployeeDetailsImpl(employees);

recyclerView = view.findViewById(R.id.recycler_view);

RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(empAdapter);

empDetails();
return view;
}

private void empDetails() {

employeePresenter.employeeDetails();
}



@Override
public void onSuccessResponseView(Response<POJO> response, String type) {

}



@Override
public void onSuccessResponseArrayView(Response<ArrayPOJO> response, String type) {

ArrayPOJO empPojoresp = response.body();

List<POJO> arrayPOJO = empPojoresp.getDetails();

for (POJO pojo : arrayPOJO) {
employeePojo = new EmployeePojo(pojo.getId(), pojo.getMobile(), pojo.getName(), pojo.getIMAGE());
employeetList.add(employeePojo);
}

recyclerView.setAdapter(new EmployeeAdapter(getActivity(), employeetList));


empAdapter.notifyDataSetChanged();
}

}

最佳答案

请修改以下代码

 Employees employees = new Employees();
employeePresenter = new EmployeeDetailsImpl(employees);

 employeePresenter = new EmployeeDetailsImpl(this);

因为您正在为同一个 fragment 创建另一个实例

关于android - Recycularview 适配器未在 MVP 模式的选项卡 fragment 中设置,显示错误没有附加适配器跳过布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53780285/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com