我需要设置一个特定卡片的点击监听器,带有回收视图和卡片布局,我需要做一些特定的东西,我怎么能实现这一点,我arleady创建了自定义适配器,但点击是还没有工作。
适配器
package com.example.afcosta.inesctec.pt.android.Adapters;
import android.content.Context;
import android.media.Image;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.afcosta.inesctec.pt.android.R;
import com.example.afcosta.inesctec.pt.android.models.Family;
import com.example.afcosta.inesctec.pt.android.models.Photo;
import com.squareup.picasso.Picasso;
import java.util.ArrayList;
/**
* Created by FilipeCosta on 29/05/2017.
*/
public class FamilyLibraryAdapter extends RecyclerView.Adapter<FamilyLibraryAdapter.ViewHolder> {
private OnItemClickListener listener;
private ArrayList<Family> families;
private Context context;
public interface OnItemClickListener {
void onRowClick(int position,String name, int id, View view);
}
public FamilyLibraryAdapter(Context context, ArrayList<Family> families,OnItemClickListener listener) {
this.families = families;
this.context = context;
this.listener = listener;
}
@Override
public FamilyLibraryAdapter.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.activity_library_families_row, viewGroup, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final FamilyLibraryAdapter.ViewHolder viewHolder, final int i) {
viewHolder.name.setText(families.get(i).getName());
String urlFoto = "http://10.0.2.2:3000" + families.get(i).getPath();
Picasso.with(context)
.load(urlFoto)
.resize(400, 400)
.into(viewHolder.img);
viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("ENTERED","ENTERED");
if (listener != null) {
Log.d("ENTERED","ENTERED");
listener.onRowClick(viewHolder.getAdapterPosition(),families.get(i).getName(), families.get(i).getId(), v);
}
}
});
}
@Override
public int getItemCount() {
return families.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
private TextView name;
private ImageView img;
public ViewHolder(View view) {
super(view);
name = (TextView) view.findViewById(R.id.namePlant);
img = (ImageView) view.findViewById(R.id.thumbnail);
}
}
}
答案 0 :(得分:0)
hash1 latest changes in foo.txt
hash3 latest changes in bar.txt