0
I’m creating a project that shows a list of equipment through a Recyclerview. When clicking on an item of this Recyclerview, you would need to open a new screen with details of the clicked item. The problem is that the itemClickListener option does not appear, even though it is declared in viewHolder.
Viewholder
public class InventarioViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
public TextView txtHd, txtHostName, txtMarca, txtMemoria, txtModelo, txtPcId, txtProcessador, txtSetor, txtSo, txtTipo, txtUsuario;
public ImageView img_user, menu_options;
private ItemClickListener itemClickListener;
public InventarioViewHolder(View itemView) {
super(itemView);
txtPcId = itemView.findViewById(R.id.pc_nome);
txtUsuario = itemView.findViewById(R.id.pc_usuario);
txtSetor = itemView.findViewById(R.id.pc_setor);
img_user = itemView.findViewById(R.id.img_user);
menu_options = itemView.findViewById(R.id.menu_options);
itemView.setOnClickListener(this);
}
@Override
public void onClick(View view) {
itemClickListener.onClick(view, getAdapterPosition(), false);
}
}
Home class.
private void loadInventario() {
adapter = new FirebaseRecyclerAdapter<Inventario, InventarioViewHolder>(Inventario.class,
R.layout.inventario_item, InventarioViewHolder.class, categories) {
@Override
protected void populateViewHolder(InventarioViewHolder viewHolder, Inventario model, int position) {
viewHolder.txtPcId.setText(model.getPcId());
viewHolder.txtUsuario.setText(model.getUsuario());
viewHolder.txtSetor.setText(model.getSetor());
Picasso.with(Home.this).load(model.getImage()).into(viewHolder.img_user);
//*********************** Após o viewHolder. deveria aparecer a opção setItemClickListener *******************
viewHolder.setItemClickListener(new ItemClickListener()){
}
}
};
adapter.notifyDataSetChanged();
recycler_inventario.setAdapter(adapter);
}
Recyclerview
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Home">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_inventario"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v7.widget.RecyclerView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
app:backgroundTint="@android:color/white"
app:srcCompat="@drawable/ic_playlist_add_black_24dp"/>
</RelativeLayout>
Layout of the Recyclerview
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="8dp">
<View
android:background="@color/colorPrimaryDark"
android:layout_width="match_parent"
android:layout_marginTop="60dp"
android:layout_height="0.6dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white">
<LinearLayout
android:layout_width="60dp"
android:layout_height="60dp"
android:orientation="horizontal">
<com.pkmmte.view.CircularImageView
android:id="@+id/img_user"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_account_circle_black_24dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="12dp"
android:orientation="vertical">
<TextView
android:id="@+id/pc_nome"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/overlayBackground"
android:text="000000"
android:textColor="@color/colorPrimaryDark"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="@+id/pc_usuario"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/overlayBackground"
android:text="Nome do usuário"
android:textColor="@color/colorPrimaryDark"
android:textSize="14sp" />
<TextView
android:id="@+id/pc_setor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="@color/overlayBackground"
android:text="Setor"
android:textColor="@color/colorPrimaryDark"
android:textSize="12sp"
android:textStyle="italic" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="350dp"
android:layout_marginTop="12dp">
<ImageView
android:id="@+id/menu_options"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/ic_more_vert_black_24dp" />
</RelativeLayout>
</RelativeLayout>
He doesn’t show up because his class
InventarioViewHolder
does not have the method. At least in the code you posted only the variable is declareditemClickListener
. Where is the Setter?– Piovezan
Thank you Piovezan.. That was it.!
– vsousa
@vsousa took my "I accept" ;-;
– Woton Sampaio