我想设置这个图标,就像用户想要标记这一章一样,因为它会读取这个图标,所以它会切换到另一个图标。
我的文件:SeptCoursAdapter.java
public class SeptCoursAdapter extends RecyclerView.Adapter<SeptCoursAdapter.MyViewHolder> {
private Context mContext;
private List<ItemSeptCours> chapList;
public class MyViewHolder extends RecyclerView.ViewHolder {
public TextView chapitreTitle;
public TextView nbHeures;
public ImageView pecLue;
public MyViewHolder(View view) {
super(view);
chapitreTitle = (TextView) view.findViewById(R.id.chapitre_title);
nbHeures = (TextView) view.findViewById(R.id.nb_heure);
pecLue = (ImageView) view.findViewById(R.id.image_lue);
}
}
public SeptCoursAdapter(Context mContext, List<ItemSeptCours> chapList) {
this.mContext = mContext;
this.chapList = chapList;
}
@Override
public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.card_item_7_cours, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
ItemSeptCours itemSeptCours = chapList.get(position);
holder.chapitreTitle.setText(itemSeptCours.getChapitreTitle());
holder.nbHeures.setText(itemSeptCours.getNbHeures());
Glide.with(mContext).load(itemSeptCours.getPecLue()).into(holder.pecLue);
holder.pecLue.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(holder.pecLue.getVisibility()== View.VISIBLE)
holder.pecLue.setVisibility(View.INVISIBLE);
}
});
}
@Override
public int getItemCount() {
return chapList.size();
}
}
CourseSeptFragment.java
public class CoursSeptBaseFragment extends Fragment {
@Nullable
private RecyclerView recyclerView;
private RecyclerView.Adapter adapter;
private List<ItemSeptCours> chapList;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.cours_sept_base_fragment, container, false);
recyclerView = (RecyclerView) view.findViewById(R.id.recyclerView_sept);
chapList = new ArrayList<>();
adapter = new SeptCoursAdapter(view.getContext(), chapList);
if (recyclerView != null) {
recyclerView.setHasFixedSize(true);
}
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setAdapter(adapter);
prepareChapitre();
return view;
}
private void prepareChapitre() {
int[] luePecTab = new int[]{
R.drawable.ic_visibility_black_18dp_blue,
R.drawable.ic_visibility_off_black_18dp_blue};
ItemSeptCours a = new ItemSeptCours("Chap 1: Ordinateur et systèmes d'exploitation", "4 séances", luePecTab[0]);
chapList.add(a);
a = new ItemSeptCours("Chap 2: Exploitations de logiciels", "4 séances", luePecTab[0]);
chapList.add(a);
a = new ItemSeptCours("Chap 3: L'Internet : Le web", "4 séances", luePecTab[0]);
chapList.add(a);
a = new ItemSeptCours("Un mini projet", "6 séances", luePecTab[0]);
chapList.add(a);
adapter.notifyDataSetChanged();
}
}