Ola pessoal preciso de uma orientação, sou iniciante em mobile, meu cenario é o seguinte:
Hoje eu listo da base de dados usando recycle e outro xml para listar meu itens de anunciosl até ai ok.
Mas eu não entendi, como e aonde implementar, o tal do OnClickListner que ao clicar em um item desta lista abra a ActivityDetalhes do layout xml que seria a activity de detalhes. Andei lendo e entendi que seri dentro do meu AnuncioHolder do ( public void onBindViewHolder(@NonNull AnunciosHolder holder, int position) fiz mas sem sucesso.
Meu Adapter esta assim:
identar texto pre-formatado em 4 espaços
public class AnuncioAdapterImagens extends RecyclerView.Adapter<AnuncioAdapterImagens.AnunciosHolder>{
List<Anuncio> listaAnuncioImg;
public AnuncioAdapterImagens(List<Anuncio> listaAnuncioImg) {
this.listaAnuncioImg = listaAnuncioImg;
}
@NonNull
@Override
public AnunciosHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View vista = LayoutInflater.from(parent.getContext()).inflate(R.layout.anime_row_item,parent,false);
RecyclerView.LayoutParams layoutParams =
new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
vista.setLayoutParams(layoutParams);
return new AnunciosHolder(vista);
}
@Override
public void onBindViewHolder(@NonNull AnunciosHolder holder, int position) {
holder.marcaAnuncio.setText(listaAnuncioImg.get(position).getMarca().toString());
holder.modeloAnuncio.setText(listaAnuncioImg.get(position).getModelo().toString());
holder.anoAnuncio.setText(listaAnuncioImg.get(position).getAno().toString());
holder.valorAnuncio.setText(listaAnuncioImg.get(position).getValor().toString());
if(listaAnuncioImg.get(position).getImagem() != null){
holder.idImagem.setImageBitmap(listaAnuncioImg.get(position).getImagem());
}else{
holder.idImagem.setImageResource(R.drawable.sem_foto);
}
}
@Override
public int getItemCount() {
return listaAnuncioImg.size();
}
public class AnunciosHolder extends RecyclerView.ViewHolder {
RelativeLayout parentLayout;
TextView codigoAnuncio,marcaAnuncio, modeloAnuncio, anoAnuncio, corAnuncio, valorAnuncio;
ImageView idImagem;
public AnunciosHolder(View itemView) {
super(itemView);
marcaAnuncio = (TextView) itemView.findViewById(R.id.marca);
modeloAnuncio = (TextView) itemView.findViewById(R.id.modelo);
anoAnuncio = (TextView) itemView.findViewById(R.id.ano);
corAnuncio = (TextView) itemView.findViewById(R.id.cor);
valorAnuncio = (TextView) itemView.findViewById(R.id.valor);
idImagem = itemView.findViewById(R.id.idImagem);
}
}
}
*Meu RecycleView - activity_main_anuncio.xml
<?xml version="1.0" encoding="utf-8"?><android.support.v7.widget.RecyclerView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/recyclerviewanuncio"
/>
Meu detalhes_anuncio.xlm
<?xml version="1.0" encoding="utf-8"?><ImageView
android:id="@+id/image_view_detail"
android:layout_width="match_parent"
android:layout_height="300dp"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/text_view_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:text="Likes: "
android:textSize="30sp" />