在我的应用中,我有一个Fragment,它实现了一个FirebaseRecyclerAdapter来列出Firebase对象。
我需要实现一个onClick方法来启动另一个包含所选对象的详细信息的片段。
我已经搜索了这个问题,但我还没有找到任何可以应用于我的场景的答案。
这是片段代码:
public class EnclaveFragment extends Fragment {
private String enclave;
private TextView mText;
private RecyclerView mListaEnclaves;
private DatabaseReference mDatabase;
public void onStart() {
super.onStart();
FirebaseRecyclerAdapter<Enclave, EnclavesViewHolder> firebaseRecyclerAdapter = new FirebaseRecyclerAdapter<Enclave, EnclavesViewHolder> (
Enclave.class,
R.layout.enclave_row,
EnclavesViewHolder.class,
mDatabase.orderByChild("Comunidad_enclave").equalTo(enclave)) {
protected void populateViewHolder(EnclavesViewHolder viewHolder, Enclave model, int position) {
viewHolder.setTitulo(model.getNombre_enclave());
viewHolder.setDescripcion(model.getDescripcion_enclave());
viewHolder.setImage(getActivity().getApplicationContext() , model.getImagen_Enclave());
}
};
mListaEnclaves.setAdapter(firebaseRecyclerAdapter);
}
public static class EnclavesViewHolder extends RecyclerView.ViewHolder {
View mView;
public EnclavesViewHolder(View itemView) {
super(itemView);
mView = itemView;
}
public void setTitulo(String titulo){
TextView titulo_enclave = (TextView) mView.findViewById(R.id.titulo_enclave);
titulo_enclave.setText(titulo);
}
public void setDescripcion(String descripcion){
TextView descripcion_enclave = (TextView) mView.findViewById(R.id.descripcion_enclave);
descripcion_enclave.setText(descripcion);
}
public void setImage(Context ctx, String imagen){
ImageView imagen_enclave = (ImageView) mView.findViewById(R.id.imagen_enclave);
Picasso.with(ctx).load(imagen).into(imagen_enclave);
}
}
public EnclaveFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Bundle bundle = getArguments();
if (bundle != null) {
enclave = bundle.getString("KEY_DETAIL", "Madrid");
Log.d("Enclave recibido",enclave);
}
View rootView = inflater.inflate(R.layout.enclave_connect, container, false);
mListaEnclaves = (RecyclerView) rootView.findViewById(R.id.lista_enclaves);
mListaEnclaves.setHasFixedSize(true);
mListaEnclaves.setLayoutManager(new LinearLayoutManager(this.getActivity()));
mDatabase = FirebaseDatabase.getInstance().getReference().child("Enclaves");
mText = (TextView) rootView.findViewById(R.id.ccaatxt);
mText.setText(enclave);
return rootView;
}
}
答案 0 :(得分:0)
为单个视图注册onClick侦听器,单击该视图时,应采取一些操作as described in this question。 RecyclerView及其适配器与处理任何子项视图上的任何事件无关。