Last active
October 10, 2019 15:31
-
-
Save Akjack7/592ff0560f7918de2117ce6bb1a6e1e3 to your computer and use it in GitHub Desktop.
Recycler view adapter y setteo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class AdapterListSurveyResults extends RecyclerView.Adapter<AdapterListSurveyResults.SurveyResultsViewHolder> { | |
| private ArrayList<ObjectSurveysAnswerList> data; | |
| public AdapterListSurveyResults(ArrayList<ObjectSurveysAnswerList> data) { | |
| this.data = data; | |
| } | |
| @NonNull | |
| @Override | |
| public SurveyResultsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) { | |
| return new SurveyResultsViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_adapter_survey_results, parent, false)); | |
| } | |
| @Override | |
| public void onBindViewHolder(@NonNull SurveyResultsViewHolder holder, final int position) { | |
| final ObjectSurveysAnswerList objAnswer = data.get(position); | |
| if(objAnswer != null) { | |
| holder.question.setText( objAnswer.getCodeQuestion()); | |
| holder.answer.setText(objAnswer.getDescription()); | |
| } | |
| } | |
| @Override | |
| public int getItemCount() { | |
| return data == null ? 0 : data.size(); | |
| } | |
| public void setList(ArrayList<ObjectSurveysAnswerList> list){ | |
| this.data = list; | |
| } | |
| public static class SurveyResultsViewHolder extends RecyclerView.ViewHolder { | |
| TextView question; | |
| TextView answer; | |
| SurveyResultsViewHolder(View itemView) { | |
| super(itemView); | |
| question = itemView.findViewById(R.id.tv_survey_result_question); | |
| answer = itemView.findViewById(R.id.tv_survey_result_answer); | |
| } | |
| } | |
| // Llamada y seteo del recycler | |
| rvSurveyList.setHasFixedSize(true); | |
| adapter = new AdapterListSurveyResults(listadoRespuestas); | |
| rvSurveyList.setAdapter(adapter); | |
| rvSurveyList.setItemAnimator(new DefaultItemAnimator()); | |
| rvSurveyList.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false)); | |
| // plantilla Adapter | |
| public class AdapterListPdf extends RecyclerView.Adapter<AdapterListPdf.PdfViewHolder> { | |
| private ArrayList<String> data; | |
| public AdapterListPdf(ArrayList<String> data) { | |
| this.data = data; | |
| } | |
| @NonNull | |
| @Override | |
| public PdfViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int i) { | |
| return new PdfViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.adapter_list_pdf, parent, false)); | |
| } | |
| @Override | |
| public void onBindViewHolder(@NonNull PdfViewHolder holder, final int position) { | |
| } | |
| public void setList() { | |
| } | |
| @Override | |
| public int getItemCount() { | |
| return data == null ? 0 : data.size(); | |
| } | |
| public static class PdfViewHolder extends RecyclerView.ViewHolder { | |
| PdfViewHolder(View itemView) { | |
| super(itemView); | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment