Advertisement
Guest User

CourseAdapter

a guest
Aug 22nd, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 3.82 KB | None | 0 0
  1. /*
  2.  * Copyright 2016 by FET
  3.  *
  4.  * Licensed under the Apache License, Version 2.0 (the "License");
  5.  * you may not use this file except in compliance with the License.
  6.  * You may obtain a copy of the License at
  7.  *
  8.  * http://www.apache.org/licenses/LICENSE-2.0
  9.  *
  10.  * Unless required by applicable law or agreed to in writing, software
  11.  * distributed under the License is distributed on an "AS IS" BASIS,
  12.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13.  * See the License for the specific language governing permissions and
  14.  * limitations under the License.
  15.  */
  16.  
  17. /*
  18.  *  Project created by FET on 6th November 2015
  19.  *  Code updated on 4th August 2016
  20.  */
  21.  
  22. /*
  23.  * Copyright 2016 by F43nd1r (https://github.com/F43nd1r)
  24.  *
  25.  * Licensed under the Apache License, Version 2.0 (the "License");
  26.  * you may not use this file except in compliance with the License.
  27.  * You may obtain a copy of the License at
  28.  *
  29.  * http://www.apache.org/licenses/LICENSE-2.0
  30.  *
  31.  * Unless required by applicable law or agreed to in writing, software
  32.  * distributed under the License is distributed on an "AS IS" BASIS,
  33.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  34.  * See the License for the specific language governing permissions and
  35.  * limitations under the License.
  36.  */
  37.  
  38. package com.FET.leonardo.scurcola;
  39.  
  40. import android.support.v7.widget.RecyclerView;
  41. import android.view.LayoutInflater;
  42. import android.view.View;
  43. import android.view.ViewGroup;
  44. import android.widget.Button;
  45. import android.widget.TextView;
  46.  
  47. import java.util.ArrayList;
  48.  
  49. public class CoursesAdapter extends RecyclerView.Adapter<CoursesAdapter.CoursesViewHolder> {
  50.  
  51.     public class CoursesViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
  52.         TextView name;
  53.         TextView counter;
  54.         Button voteButton;
  55.  
  56.         CoursesViewHolder(View itemView) {
  57.             super(itemView);
  58.             itemView.setOnClickListener(this);
  59.             name = (TextView) itemView.findViewById(R.id.textName);
  60.             counter = (TextView) itemView.findViewById(R.id.textCounter);
  61.             voteButton = (Button) itemView.findViewById(R.id.voteButton);
  62.         }
  63.  
  64.         @Override
  65.         public void onClick(View v) {
  66.             // The user may not set a click listener for list items, in which case our listener
  67.             // will be null, so we need to check for this
  68.             if (mOnEntryClickListener != null) {
  69.                 mOnEntryClickListener.onEntryClick(v, getLayoutPosition());
  70.             }
  71.         }
  72.     }
  73.  
  74.     private final ArrayList<Player> mArrayCourses;
  75.  
  76.     public CoursesAdapter(ArrayList<Player> arrayCourses) {
  77.         mArrayCourses = arrayCourses;
  78.     }
  79.  
  80.     @Override
  81.     public int getItemCount() {
  82.             return mArrayCourses.size();
  83.     }
  84.  
  85.     @Override
  86.     public CoursesViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  87.         View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.two_line_list_item_horizontal, parent, false);
  88.         return new CoursesViewHolder(view);
  89.     }
  90.  
  91.     @Override
  92.     public void onBindViewHolder(CoursesViewHolder holder, int position) {
  93.         Player player = mArrayCourses.get(position);
  94.         holder.name.setText(player.getName());
  95.         holder.counter.setText(String.valueOf(player.getCount()));
  96.     }
  97.  
  98.     @Override
  99.     public void onAttachedToRecyclerView(RecyclerView recyclerView) {
  100.         super.onAttachedToRecyclerView(recyclerView);
  101.     }
  102.  
  103.  
  104.     private OnEntryClickListener mOnEntryClickListener;
  105.  
  106.     public interface OnEntryClickListener {
  107.         void onEntryClick(View view, int position);
  108.     }
  109.  
  110.     public void setOnEntryClickListener(OnEntryClickListener onEntryClickListener) {
  111.         mOnEntryClickListener = onEntryClickListener;
  112.     }
  113.  
  114.  
  115.  
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement