Ich möchte @Dharma Kshetri und @Rahul Pareta für ihre Antworten danken. Danke Dies ist die Lösung:
public class Platos_Adapter extends RecyclerView.Adapter<Platos_Adapter.ViewHolder> {
private ImageLoader imageLoader;
private Context context;
List<Estadisticas> estadisticas;
public Platos_Adapter(List<Estadisticas> estadisticas, Context context) {
super();
this.estadisticas = estadisticas;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.platos_row, parent, false);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;
}
public void onBindViewHolder(ViewHolder holder, final int position) {
holder.root.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(context, estadisticas.get(position).getEquipo_Local(), Toast.LENGTH_SHORT).show();
Estadisticas estadisticas1 = estadisticas.get(getAdapterPosition());
}
private int getAdapterPosition() {
return 0;
}
});
Estadisticas superHero = estadisticas.get(position);
imageLoader = DecoracionLineaDivisoria.CustomVolleyRequest.getInstance(context).getImageLoader();
imageLoader.get(superHero.getEscudo_Local(), ImageLoader.getImageListener(holder.escudo_local, R.mipmap.ic_launcher, android.R.drawable.ic_dialog_alert));
holder.escudo_local.setImageUrl(superHero.getEscudo_Local(), imageLoader);
holder.textViewEquipo_Local.setText(superHero.getEquipo_Local());
}
@Override
public int getItemCount() {
return estadisticas.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
public NetworkImageView escudo_local;
public TextView textViewEquipo_Local;
public View root;
public ViewHolder(View itemView) {
super(itemView);
root = itemView;
escudo_local = (NetworkImageView) itemView.findViewById(R.id.tv_esc_local);
textViewEquipo_Local = (TextView) itemView.findViewById(R.id.tv_ek_local);
textViewCategoria = (TextView) itemView.findViewById(R.id.tv_ek_visi);
}
}
}
Und activity_detail.xml
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingTop="24dp">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/card_margin">
<LinearLayout
style="@style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_info_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="yyyyyyyyyyyyyyyyyy"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
<TextView
android:id="@+id/tv_info"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ddddddddddddddd" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/card_margin"
android:layout_marginLeft="@dimen/card_margin"
android:layout_marginRight="@dimen/card_margin">
<LinearLayout
style="@style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tv_categoria_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="mmmmmmmmmmmmmmmmmmm"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
<TextView
android:id="@+id/tv_categoria"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="aaaaaaaaaaaaaaaaaaaaaa" />
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/card_margin"
android:layout_marginLeft="@dimen/card_margin"
android:layout_marginRight="@dimen/card_margin">
<LinearLayout
style="@style/Widget.CardContent"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="xxxxxxxxxxxxxxxxx"
android:textAppearance="@style/TextAppearance.AppCompat.Title" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ddddddddddd" />
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Und PlatosAdapter.java
public class Platos_Adapter extends RecyclerView.Adapter<Platos_Adapter.ViewHolder> {
private ImageLoader imageLoader;
private Context context;
List<Estadisticas> estadisticas;
public Platos_Adapter(List<Estadisticas> estadisticas, Context context) {
super();
this.estadisticas = estadisticas;
this.context = context;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.platos_row, parent, false);
ViewHolder viewHolder = new ViewHolder(v);
return viewHolder;
}
public void onBindViewHolder(ViewHolder holder, final int position) {
holder.root.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
//Toast.makeText(context, "this is my Toast message!!! =)",
//Toast.LENGTH_LONG).show();
//Toast.makeText(context, estadisticas.get(position).getEquipo_Local(), Toast.LENGTH_SHORT).show();
Intent intent= new Intent(context, DetailActivity.class);
intent.putExtra("Nombre", estadisticas.get(position).getEquipo_Local());
intent.putExtra("Categoria", estadisticas.get(position).getEquipo_Visitante());
intent.putExtra("Imagen", estadisticas.get(position).getEscudo_Local());
context.startActivity(intent);
Estadisticas estadisticas1 = estadisticas.get(getAdapterPosition());
}
private int getAdapterPosition() {
return 0;
}
});
Estadisticas superHero = estadisticas.get(position);
imageLoader = DecoracionLineaDivisoria.CustomVolleyRequest.getInstance(context).getImageLoader();
imageLoader.get(superHero.getEscudo_Local(), ImageLoader.getImageListener(holder.escudo_local, R.mipmap.ic_launcher, android.R.drawable.ic_dialog_alert));
holder.escudo_local.setImageUrl(superHero.getEscudo_Local(), imageLoader);
holder.textViewEquipo_Local.setText(superHero.getEquipo_Local());
//holder.textViewCategoria.setText(superHero.getEquipo_Visitante());
}
@Override
public int getItemCount() {
return estadisticas.size();
}
class ViewHolder extends RecyclerView.ViewHolder {
public NetworkImageView escudo_local;
public TextView textViewEquipo_Local;
//public TextView textViewCategoria;
public View root;
public ViewHolder(View itemView) {
super(itemView);
root = itemView;
escudo_local = (NetworkImageView) itemView.findViewById(R.id.tv_esc_local);
textViewEquipo_Local = (TextView) itemView.findViewById(R.id.tv_ek_local);
//textViewCategoria = (TextView) itemView.findViewById(R.id.tv_ek_visi);
}
}
}
Anstatt den 'OnClickListener' auf den' viewHolder' zu setzen, sollten Sie ihn innerhalb des ViewHolders auf eine 'view' setzen, also entweder' NetWorkImageView' oder 'TextView'. Sie können auch die onClick Zuhörer auf die ganze Sicht des einzelnen Artikel hinzufügen, indem Sie die OnClickListener zu der Ansicht hinzugefügt, nachdem Sie es aufgeblasen haben in 'onCreateViewHolder' –
diesen Link zu sehen: http://stackoverflow.com/questions/24885223/why -doesnt-recyclerview-have-onitemclicklistener-und-how-recyclerview-is-dif es hat eine detail-implementierung – rafsanahmad007