首页 > 解决方案 > 如何输入参数来获取请求?

问题描述

它尝试显示通过 GET 命令分配给用户的笔记列表。从 PHP 方面来看,一切正常,但我不知道如何在 android studio 中对其进行编程?如何将参数放入 GET 请求?

 @GET("allnotesuser/{user}")
    Call<NotesUserResponse> getAllNotesUser(
            @Path("user") int user
    );

用户片段

  @Override
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        User user = SharedPrefManager.getInstance(getActivity()).getUser();

        Call<NotesUserResponse> call = RetrofitClient.getInstance().getApi().getAllNotesUser(user.getusers_id());

        recyclerView = view.findViewById(R.id.recycler_view_notes_user);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));



        call.enqueue(new Callback<NotesUserResponse>() {
            @Override
            public void onResponse(Call<NotesUserResponse> call, Response<NotesUserResponse> response) {

                notesUserList= response.body().getAllNotesUser();
                adapterNotesUser = new NotesUserAdapter(getActivity(),notesUserList);
                recyclerView.setAdapter(adapterNotesUser);
            }

            @Override
            public void onFailure(Call<NotesUserResponse> call, Throwable t) {

            }
        });
        }

在这一行中,我收到错误“revylerview.setLayoutManager 为空”

recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));

标签: javaandroidgetretrofit2

解决方案


推荐阅读