android翻新获取带有参数的请求

时间:2019-03-21 11:20:59

标签: android get request

在我的回收站视图中,我有主题名称及其ID。当在recyclerview上单击任何主题时,然后传递该ID以使用参数获取请求,并根据该ID获取json数据。我被卡住了,请帮助我

public class SubjectAdapter extends RecyclerView.Adapter<SubjectAdapter.CustomViewHolder> {
    private List<Subjects> subjects;

    public SubjectAdapter(List<Subjects> subjects) {
        this.subjects = subjects;
    }

    @NonNull
    @Override
    public CustomViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View itemView = LayoutInflater.from(viewGroup.getContext())
                .inflate(R.layout.subject_list, viewGroup, false);

        return new CustomViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull CustomViewHolder customViewHolder, int i) {
        Subjects subject = subjects.get(i);
        customViewHolder.subjectname.setText(subject.getSubjectName());
        customViewHolder.imagename.setText(subject.getImgPath());
        customViewHolder.createdat.setText(subject.getId().toString());

    }

    @Override
    public int getItemCount() {
        return subjects.size();
    }

    public class CustomViewHolder extends RecyclerView.ViewHolder{
        public TextView subjectname,imagename,createdat,updatedat;
        ImageView imageView;

        public CustomViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView = (ImageView) itemView.findViewById(R.id.imageView);
            subjectname = (TextView) itemView.findViewById(R.id.subName);
            imagename = (TextView) itemView.findViewById(R.id.imgname);
            createdat = (TextView) itemView.findViewById(R.id.subject_id);
        }
    }
}

Api界面

@GET("subject/computer-science/237")
Call<SubjectList> getLevel();

0 个答案:

没有答案