It is as follows, I created a Adapter
that changes a RecyclerView
in an Activity that I call through this function (within the activity):
private void gerarDatasView(CalendarJur calendario){
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.HORIZONTAL, false);
listDatas.setLayoutManager(linearLayoutManager);
ListDatasAdapter adapter = new ListDatasAdapter();
adapter.setDateJur(calendario.getDatas());
listDatas.setAdapter(adapter);
}
The listDatas
is the RecyclerView
.
And it works perfectly according to the image:
EachiteminthislistwascreatedusingonBindViewHolder
inmyAdapterlikethis:
publicvoidonBindViewHolder(@NonNullfinalViewListDatasholder,intposition){DateJurdata=datas.get(position);holder.diaMes.setText(data.getDiaMes());holder.diaSemana.setText(data.getDiaSemana());if(holder.getAdapterPosition()==posNow){holder.btn.setImageResource(R.drawable.background_date_layout_selected);posNow=holder.getAdapterPosition();}holder.btn.setOnClickListener(newView.OnClickListener(){@OverridepublicvoidonClick(Viewv){holder.btn.setImageResource(R.drawable.background_date_layout_selected);//mudaacordefundoconformeoclick}});}
WhenIclickonanotherdatethebackgroundcolorchangesthewayIwant,buttheolddatewouldhavetobewiththedefaultbackground,butbothwillhavethebackgroundselected(blue)see:
/p>
My question:
How do I make the adapter know that it has to change the other item to the default color after a click?
Can you control this within the Adapter or would I have to do it differently?
As I did not want to leave the question very extensive, I put the codes that I think are necessary, but if you need other information just ask.