Nao consigo executar o OnClickListener no meu código na List do RecycleView

  • Respostas:0
G_Cristiano Gaspar
  • Posts no fórum: 2

05/06/2018, 17:46:44 via Web

Tentei por varios tutoriais , li e estudei a implementação mas não consegui que funcionasse.
Tenho minha activity que gera a lista de itens no recycleView, nesta activity contem o metodo que traz as informações da base em JSON

## **consultarListaAnunciosImagem**
 public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    // Inflate the layout for this fragment

    View vista = inflater.inflate(R.layout.activity_recycle_main_do_anime, container, false);
    listaAnuncios=new ArrayList<>();
    recyclerAnuncio= (RecyclerView) vista.findViewById(R.id.recyclerviewid);
    recyclerAnuncio.setLayoutManager(new LinearLayoutManager(this.getContext()));
    recyclerAnuncio.setHasFixedSize(true);

    request= Volley.newRequestQueue(getContext());
    carregarWEBService();
    return vista;
}

private void carregarWEBService() {
    progresso = new ProgressDialog(getContext());
    progresso.setMessage("Buscando...");
    progresso.show();

    //String url = "chamaMinha Base com os dados por JSON";


    jsonObjectReq = new JsonObjectRequest(Request.Method.GET, url, null, this, this);
    request.add(jsonObjectReq);
}


// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
    if (mListener != null) {
        mListener.onFragmentInteraction(uri);
    }
}

@Override
public void onAttach(Context context) {
    super.onAttach(context);
    if (context instanceof consultarListaAnunciosImagem.OnFragmentInteractionListener) {
        mListener = (consultarListaAnunciosImagem.OnFragmentInteractionListener) context;
    } else {
        throw new RuntimeException(context.toString()
                + " must implement OnFragmentInteractionListener");
    }
}

Até ai tudo ok, ai tenho Adapter que exibe as informações para o Recycle com outro aqruivo que é o List e este adapter gerar todos certinho, minha duvida é como clicar num item e este item abrir a activity_detalhes_anuncio com o xml detalhes_anuncio.xml exibindo as info do item que eu cliquei

Segue o adapter

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);

    }
}

Andei olhando e teria de chamar dentro do onBindViewHolder o OnClickListener mas nao funcionou para mim

Seja o primeiro a responder