Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
706 views
in Technique[技术] by (71.8m points)

android - Firebase UI RecyclerView onClick

I am using Firebase UI FirebaseRecyclerAdapter to populate a RecyclerView. I managed to get click events from components of my item view (the title), but not for anywhere in the item view, which is what I need. I followed google sample.

In my Activity:

private void setRecyclerView() {
    recyclerView = (RecyclerView) findViewById(R.id.recycler_view_gigs);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    mAdapter = new FirebaseRecyclerAdapter<Gig, GigViewHolder>(Gig.class,
            R.layout.list_item_card,
            GigViewHolder.class,
            reference) {
        @Override
        protected void populateViewHolder(final GigViewHolder viewGig, Gig model, final int position) {

            viewGig.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.i(Utils.TAG, "onItemClickGeneral: position " + position);
                    // this doesn't work
                }
            });
            viewGig.bindToGig(model, new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Log.i(Utils.TAG, "onItemClickTitle: position " + position);
                    // this works
                }
            });
        }
    };
    recyclerView.setAdapter(mAdapter);
}

and my ViewHolderClass:

public class GigViewHolder extends RecyclerView.ViewHolder {

ImageView ivIconArtist;
TextView tvArtist;
TextView tvVenue;
TextView tvDate;

public GigViewHolder(View view) {
    super(view);
    ivIconArtist = (ImageView) view.findViewById(R.id.iv_list_item_icon_artist);
    tvArtist = (TextView) view.findViewById(R.id.tv_list_item_artist);
    tvVenue = (TextView) view.findViewById(R.id.tv_list_item_venue);
    tvDate = (TextView) view.findViewById(R.id.tv_list_item_date);
}

public void bindToGig(Gig gig, View.OnClickListener clickListener) {
    tvArtist.setText(gig.getArtist());
    tvVenue.setText(gig.getVenue());
    tvDate.setText(gig.getDate());

    tvArtist.setOnClickListener(clickListener);
}

}

I tried the custom onclicklistener + interface suggested in other answers, no luck either.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...