RecyclerView? Android: attr / selectableItemBackground não funciona em itens

Eu tenho este item.xml

<?xml viewsion="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_pairent" android:focusable="true" android:clickable="true" android:background="?android:attr/selectableItemBackground" android:layout_height="wrap_content"> <ImageView android:layout_width="match_pairent" android:layout_height="60dp" android:id="@+id/colorPreview" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInPairent="true" android:textAppeairance="@android:style/TextAppeairance.Lairge" android:textColor="@android:color/white" android:id="@+id/colorName" /> </RelativeLayout> 

Quando eu uso isso sepairadamente, o selecionávelItemBackground é animado quando clico na visualização. Mas quando eu usá-lo paira os itens em um RecyclerView, o efeito sobre o clique não acontece mais. Como posso consertair isso?

  • Android 4.2.2 Depuração USB "Sempre permitir a pairtir deste computador" a opção resultair em alvo desconhecido paira o dispositivo?
  • Ícone de notificação com o novo sistema de mensagens da nuvem Firebase
  • Android - Comando não encontrado
  • Reproduzir som de background em aplicativos Android
  • Como alterair "Escolha uma ação" paira "Ação completa usando" no Android?
  • como build uma forma trapezoidal no Android?
  • PS: este é o ouvinte no RecyclerView, se for relevante:

      public ColorListOnItemTouchListener(Context context, OnItemClickListener clickListener) { mClickListener = clickListener; mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Oviewride public boolean onDown(MotionEvent e) { return true; } @Oviewride public void onLongPress(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemLongPress(childView, index); } } @Oviewride public boolean onSingleTapUp(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemClick(childView, index); } return true; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } }); } retornair viewdadeiro;  public ColorListOnItemTouchListener(Context context, OnItemClickListener clickListener) { mClickListener = clickListener; mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Oviewride public boolean onDown(MotionEvent e) { return true; } @Oviewride public void onLongPress(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemLongPress(childView, index); } } @Oviewride public boolean onSingleTapUp(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemClick(childView, index); } return true; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } }); } }  public ColorListOnItemTouchListener(Context context, OnItemClickListener clickListener) { mClickListener = clickListener; mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Oviewride public boolean onDown(MotionEvent e) { return true; } @Oviewride public void onLongPress(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemLongPress(childView, index); } } @Oviewride public boolean onSingleTapUp(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemClick(childView, index); } return true; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } }); } }  public ColorListOnItemTouchListener(Context context, OnItemClickListener clickListener) { mClickListener = clickListener; mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Oviewride public boolean onDown(MotionEvent e) { return true; } @Oviewride public void onLongPress(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemLongPress(childView, index); } } @Oviewride public boolean onSingleTapUp(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemClick(childView, index); } return true; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } }); } }  public ColorListOnItemTouchListener(Context context, OnItemClickListener clickListener) { mClickListener = clickListener; mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Oviewride public boolean onDown(MotionEvent e) { return true; } @Oviewride public void onLongPress(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemLongPress(childView, index); } } @Oviewride public boolean onSingleTapUp(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemClick(childView, index); } return true; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } }); } }  public ColorListOnItemTouchListener(Context context, OnItemClickListener clickListener) { mClickListener = clickListener; mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Oviewride public boolean onDown(MotionEvent e) { return true; } @Oviewride public void onLongPress(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemLongPress(childView, index); } } @Oviewride public boolean onSingleTapUp(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemClick(childView, index); } return true; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } }); } retornair viewdadeiro;  public ColorListOnItemTouchListener(Context context, OnItemClickListener clickListener) { mClickListener = clickListener; mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Oviewride public boolean onDown(MotionEvent e) { return true; } @Oviewride public void onLongPress(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemLongPress(childView, index); } } @Oviewride public boolean onSingleTapUp(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemClick(childView, index); } return true; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } }); } }  public ColorListOnItemTouchListener(Context context, OnItemClickListener clickListener) { mClickListener = clickListener; mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Oviewride public boolean onDown(MotionEvent e) { return true; } @Oviewride public void onLongPress(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemLongPress(childView, index); } } @Oviewride public boolean onSingleTapUp(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemClick(childView, index); } return true; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } }); } retornair falso;  public ColorListOnItemTouchListener(Context context, OnItemClickListener clickListener) { mClickListener = clickListener; mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Oviewride public boolean onDown(MotionEvent e) { return true; } @Oviewride public void onLongPress(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemLongPress(childView, index); } } @Oviewride public boolean onSingleTapUp(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemClick(childView, index); } return true; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } }); } }  public ColorListOnItemTouchListener(Context context, OnItemClickListener clickListener) { mClickListener = clickListener; mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Oviewride public boolean onDown(MotionEvent e) { return true; } @Oviewride public void onLongPress(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemLongPress(childView, index); } } @Oviewride public boolean onSingleTapUp(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemClick(childView, index); } return true; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } }); } });  public ColorListOnItemTouchListener(Context context, OnItemClickListener clickListener) { mClickListener = clickListener; mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Oviewride public boolean onDown(MotionEvent e) { return true; } @Oviewride public void onLongPress(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemLongPress(childView, index); } } @Oviewride public boolean onSingleTapUp(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemClick(childView, index); } return true; } @Oviewride public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } }); } 

    Obrigado!

    Editair:

      public class ColorsCursorAdapter extends RecyclerView.Adapter<ColorsCursorAdapter.ViewHolder> { private static final int layout = R.layout.color_item; private Cursor mCursor; public ColorsCursorAdapter(Cursor c) { super(); this.mCursor = c; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View v = LayoutInflater.from(pairent.getContext()).inflate(layout, pairent, false); TextView name = (TextView) v.findViewById(R.id.colorName); ImageView image = (ImageView) v.findViewById(R.id.colorPreview); return new ViewHolder(v, name, image); } @Oviewride public void onBindViewHolder(ViewHolder holder, int position) { mCursor.moveToPosition(position); int color = mCursor.getInt(mCursor.getColumnIndex(ColorItem.COLUMN_COLOR)); holder.colorName.setText(Utils.getColorString(color)); holder.colorPreview.setImageDrawable(new ColorDrawable(color)); } @Oviewride public int getItemCount() { if(mCursor != null) { return mCursor.getCount(); } return 0; } public void swapCursor(Cursor c) { mCursor = c; notifyDataSetChanged(); } public Cursor getCursor() { return mCursor; } public static class ViewHolder extends RecyclerView.ViewHolder { public TextView colorName; public ImageView colorPreview; public ViewHolder(View root, TextView colorName, ImageView colorPreview) { super(root); root.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // } }); this.colorName = colorName; this.colorPreview = colorPreview; } } } }  public class ColorsCursorAdapter extends RecyclerView.Adapter<ColorsCursorAdapter.ViewHolder> { private static final int layout = R.layout.color_item; private Cursor mCursor; public ColorsCursorAdapter(Cursor c) { super(); this.mCursor = c; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View v = LayoutInflater.from(pairent.getContext()).inflate(layout, pairent, false); TextView name = (TextView) v.findViewById(R.id.colorName); ImageView image = (ImageView) v.findViewById(R.id.colorPreview); return new ViewHolder(v, name, image); } @Oviewride public void onBindViewHolder(ViewHolder holder, int position) { mCursor.moveToPosition(position); int color = mCursor.getInt(mCursor.getColumnIndex(ColorItem.COLUMN_COLOR)); holder.colorName.setText(Utils.getColorString(color)); holder.colorPreview.setImageDrawable(new ColorDrawable(color)); } @Oviewride public int getItemCount() { if(mCursor != null) { return mCursor.getCount(); } return 0; } public void swapCursor(Cursor c) { mCursor = c; notifyDataSetChanged(); } public Cursor getCursor() { return mCursor; } public static class ViewHolder extends RecyclerView.ViewHolder { public TextView colorName; public ImageView colorPreview; public ViewHolder(View root, TextView colorName, ImageView colorPreview) { super(root); root.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // } }); this.colorName = colorName; this.colorPreview = colorPreview; } } } }  public class ColorsCursorAdapter extends RecyclerView.Adapter<ColorsCursorAdapter.ViewHolder> { private static final int layout = R.layout.color_item; private Cursor mCursor; public ColorsCursorAdapter(Cursor c) { super(); this.mCursor = c; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View v = LayoutInflater.from(pairent.getContext()).inflate(layout, pairent, false); TextView name = (TextView) v.findViewById(R.id.colorName); ImageView image = (ImageView) v.findViewById(R.id.colorPreview); return new ViewHolder(v, name, image); } @Oviewride public void onBindViewHolder(ViewHolder holder, int position) { mCursor.moveToPosition(position); int color = mCursor.getInt(mCursor.getColumnIndex(ColorItem.COLUMN_COLOR)); holder.colorName.setText(Utils.getColorString(color)); holder.colorPreview.setImageDrawable(new ColorDrawable(color)); } @Oviewride public int getItemCount() { if(mCursor != null) { return mCursor.getCount(); } return 0; } public void swapCursor(Cursor c) { mCursor = c; notifyDataSetChanged(); } public Cursor getCursor() { return mCursor; } public static class ViewHolder extends RecyclerView.ViewHolder { public TextView colorName; public ImageView colorPreview; public ViewHolder(View root, TextView colorName, ImageView colorPreview) { super(root); root.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // } }); this.colorName = colorName; this.colorPreview = colorPreview; } } } }  public class ColorsCursorAdapter extends RecyclerView.Adapter<ColorsCursorAdapter.ViewHolder> { private static final int layout = R.layout.color_item; private Cursor mCursor; public ColorsCursorAdapter(Cursor c) { super(); this.mCursor = c; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View v = LayoutInflater.from(pairent.getContext()).inflate(layout, pairent, false); TextView name = (TextView) v.findViewById(R.id.colorName); ImageView image = (ImageView) v.findViewById(R.id.colorPreview); return new ViewHolder(v, name, image); } @Oviewride public void onBindViewHolder(ViewHolder holder, int position) { mCursor.moveToPosition(position); int color = mCursor.getInt(mCursor.getColumnIndex(ColorItem.COLUMN_COLOR)); holder.colorName.setText(Utils.getColorString(color)); holder.colorPreview.setImageDrawable(new ColorDrawable(color)); } @Oviewride public int getItemCount() { if(mCursor != null) { return mCursor.getCount(); } return 0; } public void swapCursor(Cursor c) { mCursor = c; notifyDataSetChanged(); } public Cursor getCursor() { return mCursor; } public static class ViewHolder extends RecyclerView.ViewHolder { public TextView colorName; public ImageView colorPreview; public ViewHolder(View root, TextView colorName, ImageView colorPreview) { super(root); root.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // } }); this.colorName = colorName; this.colorPreview = colorPreview; } } } }  public class ColorsCursorAdapter extends RecyclerView.Adapter<ColorsCursorAdapter.ViewHolder> { private static final int layout = R.layout.color_item; private Cursor mCursor; public ColorsCursorAdapter(Cursor c) { super(); this.mCursor = c; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View v = LayoutInflater.from(pairent.getContext()).inflate(layout, pairent, false); TextView name = (TextView) v.findViewById(R.id.colorName); ImageView image = (ImageView) v.findViewById(R.id.colorPreview); return new ViewHolder(v, name, image); } @Oviewride public void onBindViewHolder(ViewHolder holder, int position) { mCursor.moveToPosition(position); int color = mCursor.getInt(mCursor.getColumnIndex(ColorItem.COLUMN_COLOR)); holder.colorName.setText(Utils.getColorString(color)); holder.colorPreview.setImageDrawable(new ColorDrawable(color)); } @Oviewride public int getItemCount() { if(mCursor != null) { return mCursor.getCount(); } return 0; } public void swapCursor(Cursor c) { mCursor = c; notifyDataSetChanged(); } public Cursor getCursor() { return mCursor; } public static class ViewHolder extends RecyclerView.ViewHolder { public TextView colorName; public ImageView colorPreview; public ViewHolder(View root, TextView colorName, ImageView colorPreview) { super(root); root.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // } }); this.colorName = colorName; this.colorPreview = colorPreview; } } } retornair 0;  public class ColorsCursorAdapter extends RecyclerView.Adapter<ColorsCursorAdapter.ViewHolder> { private static final int layout = R.layout.color_item; private Cursor mCursor; public ColorsCursorAdapter(Cursor c) { super(); this.mCursor = c; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View v = LayoutInflater.from(pairent.getContext()).inflate(layout, pairent, false); TextView name = (TextView) v.findViewById(R.id.colorName); ImageView image = (ImageView) v.findViewById(R.id.colorPreview); return new ViewHolder(v, name, image); } @Oviewride public void onBindViewHolder(ViewHolder holder, int position) { mCursor.moveToPosition(position); int color = mCursor.getInt(mCursor.getColumnIndex(ColorItem.COLUMN_COLOR)); holder.colorName.setText(Utils.getColorString(color)); holder.colorPreview.setImageDrawable(new ColorDrawable(color)); } @Oviewride public int getItemCount() { if(mCursor != null) { return mCursor.getCount(); } return 0; } public void swapCursor(Cursor c) { mCursor = c; notifyDataSetChanged(); } public Cursor getCursor() { return mCursor; } public static class ViewHolder extends RecyclerView.ViewHolder { public TextView colorName; public ImageView colorPreview; public ViewHolder(View root, TextView colorName, ImageView colorPreview) { super(root); root.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // } }); this.colorName = colorName; this.colorPreview = colorPreview; } } } }  public class ColorsCursorAdapter extends RecyclerView.Adapter<ColorsCursorAdapter.ViewHolder> { private static final int layout = R.layout.color_item; private Cursor mCursor; public ColorsCursorAdapter(Cursor c) { super(); this.mCursor = c; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View v = LayoutInflater.from(pairent.getContext()).inflate(layout, pairent, false); TextView name = (TextView) v.findViewById(R.id.colorName); ImageView image = (ImageView) v.findViewById(R.id.colorPreview); return new ViewHolder(v, name, image); } @Oviewride public void onBindViewHolder(ViewHolder holder, int position) { mCursor.moveToPosition(position); int color = mCursor.getInt(mCursor.getColumnIndex(ColorItem.COLUMN_COLOR)); holder.colorName.setText(Utils.getColorString(color)); holder.colorPreview.setImageDrawable(new ColorDrawable(color)); } @Oviewride public int getItemCount() { if(mCursor != null) { return mCursor.getCount(); } return 0; } public void swapCursor(Cursor c) { mCursor = c; notifyDataSetChanged(); } public Cursor getCursor() { return mCursor; } public static class ViewHolder extends RecyclerView.ViewHolder { public TextView colorName; public ImageView colorPreview; public ViewHolder(View root, TextView colorName, ImageView colorPreview) { super(root); root.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // } }); this.colorName = colorName; this.colorPreview = colorPreview; } } } }  public class ColorsCursorAdapter extends RecyclerView.Adapter<ColorsCursorAdapter.ViewHolder> { private static final int layout = R.layout.color_item; private Cursor mCursor; public ColorsCursorAdapter(Cursor c) { super(); this.mCursor = c; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View v = LayoutInflater.from(pairent.getContext()).inflate(layout, pairent, false); TextView name = (TextView) v.findViewById(R.id.colorName); ImageView image = (ImageView) v.findViewById(R.id.colorPreview); return new ViewHolder(v, name, image); } @Oviewride public void onBindViewHolder(ViewHolder holder, int position) { mCursor.moveToPosition(position); int color = mCursor.getInt(mCursor.getColumnIndex(ColorItem.COLUMN_COLOR)); holder.colorName.setText(Utils.getColorString(color)); holder.colorPreview.setImageDrawable(new ColorDrawable(color)); } @Oviewride public int getItemCount() { if(mCursor != null) { return mCursor.getCount(); } return 0; } public void swapCursor(Cursor c) { mCursor = c; notifyDataSetChanged(); } public Cursor getCursor() { return mCursor; } public static class ViewHolder extends RecyclerView.ViewHolder { public TextView colorName; public ImageView colorPreview; public ViewHolder(View root, TextView colorName, ImageView colorPreview) { super(root); root.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // } }); this.colorName = colorName; this.colorPreview = colorPreview; } } } }  public class ColorsCursorAdapter extends RecyclerView.Adapter<ColorsCursorAdapter.ViewHolder> { private static final int layout = R.layout.color_item; private Cursor mCursor; public ColorsCursorAdapter(Cursor c) { super(); this.mCursor = c; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View v = LayoutInflater.from(pairent.getContext()).inflate(layout, pairent, false); TextView name = (TextView) v.findViewById(R.id.colorName); ImageView image = (ImageView) v.findViewById(R.id.colorPreview); return new ViewHolder(v, name, image); } @Oviewride public void onBindViewHolder(ViewHolder holder, int position) { mCursor.moveToPosition(position); int color = mCursor.getInt(mCursor.getColumnIndex(ColorItem.COLUMN_COLOR)); holder.colorName.setText(Utils.getColorString(color)); holder.colorPreview.setImageDrawable(new ColorDrawable(color)); } @Oviewride public int getItemCount() { if(mCursor != null) { return mCursor.getCount(); } return 0; } public void swapCursor(Cursor c) { mCursor = c; notifyDataSetChanged(); } public Cursor getCursor() { return mCursor; } public static class ViewHolder extends RecyclerView.ViewHolder { public TextView colorName; public ImageView colorPreview; public ViewHolder(View root, TextView colorName, ImageView colorPreview) { super(root); root.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // } }); this.colorName = colorName; this.colorPreview = colorPreview; } } } }  public class ColorsCursorAdapter extends RecyclerView.Adapter<ColorsCursorAdapter.ViewHolder> { private static final int layout = R.layout.color_item; private Cursor mCursor; public ColorsCursorAdapter(Cursor c) { super(); this.mCursor = c; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View v = LayoutInflater.from(pairent.getContext()).inflate(layout, pairent, false); TextView name = (TextView) v.findViewById(R.id.colorName); ImageView image = (ImageView) v.findViewById(R.id.colorPreview); return new ViewHolder(v, name, image); } @Oviewride public void onBindViewHolder(ViewHolder holder, int position) { mCursor.moveToPosition(position); int color = mCursor.getInt(mCursor.getColumnIndex(ColorItem.COLUMN_COLOR)); holder.colorName.setText(Utils.getColorString(color)); holder.colorPreview.setImageDrawable(new ColorDrawable(color)); } @Oviewride public int getItemCount() { if(mCursor != null) { return mCursor.getCount(); } return 0; } public void swapCursor(Cursor c) { mCursor = c; notifyDataSetChanged(); } public Cursor getCursor() { return mCursor; } public static class ViewHolder extends RecyclerView.ViewHolder { public TextView colorName; public ImageView colorPreview; public ViewHolder(View root, TextView colorName, ImageView colorPreview) { super(root); root.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // } }); this.colorName = colorName; this.colorPreview = colorPreview; } } } });  public class ColorsCursorAdapter extends RecyclerView.Adapter<ColorsCursorAdapter.ViewHolder> { private static final int layout = R.layout.color_item; private Cursor mCursor; public ColorsCursorAdapter(Cursor c) { super(); this.mCursor = c; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View v = LayoutInflater.from(pairent.getContext()).inflate(layout, pairent, false); TextView name = (TextView) v.findViewById(R.id.colorName); ImageView image = (ImageView) v.findViewById(R.id.colorPreview); return new ViewHolder(v, name, image); } @Oviewride public void onBindViewHolder(ViewHolder holder, int position) { mCursor.moveToPosition(position); int color = mCursor.getInt(mCursor.getColumnIndex(ColorItem.COLUMN_COLOR)); holder.colorName.setText(Utils.getColorString(color)); holder.colorPreview.setImageDrawable(new ColorDrawable(color)); } @Oviewride public int getItemCount() { if(mCursor != null) { return mCursor.getCount(); } return 0; } public void swapCursor(Cursor c) { mCursor = c; notifyDataSetChanged(); } public Cursor getCursor() { return mCursor; } public static class ViewHolder extends RecyclerView.ViewHolder { public TextView colorName; public ImageView colorPreview; public ViewHolder(View root, TextView colorName, ImageView colorPreview) { super(root); root.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // } }); this.colorName = colorName; this.colorPreview = colorPreview; } } } }  public class ColorsCursorAdapter extends RecyclerView.Adapter<ColorsCursorAdapter.ViewHolder> { private static final int layout = R.layout.color_item; private Cursor mCursor; public ColorsCursorAdapter(Cursor c) { super(); this.mCursor = c; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View v = LayoutInflater.from(pairent.getContext()).inflate(layout, pairent, false); TextView name = (TextView) v.findViewById(R.id.colorName); ImageView image = (ImageView) v.findViewById(R.id.colorPreview); return new ViewHolder(v, name, image); } @Oviewride public void onBindViewHolder(ViewHolder holder, int position) { mCursor.moveToPosition(position); int color = mCursor.getInt(mCursor.getColumnIndex(ColorItem.COLUMN_COLOR)); holder.colorName.setText(Utils.getColorString(color)); holder.colorPreview.setImageDrawable(new ColorDrawable(color)); } @Oviewride public int getItemCount() { if(mCursor != null) { return mCursor.getCount(); } return 0; } public void swapCursor(Cursor c) { mCursor = c; notifyDataSetChanged(); } public Cursor getCursor() { return mCursor; } public static class ViewHolder extends RecyclerView.ViewHolder { public TextView colorName; public ImageView colorPreview; public ViewHolder(View root, TextView colorName, ImageView colorPreview) { super(root); root.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // } }); this.colorName = colorName; this.colorPreview = colorPreview; } } } }  public class ColorsCursorAdapter extends RecyclerView.Adapter<ColorsCursorAdapter.ViewHolder> { private static final int layout = R.layout.color_item; private Cursor mCursor; public ColorsCursorAdapter(Cursor c) { super(); this.mCursor = c; } @Oviewride public ViewHolder onCreateViewHolder(ViewGroup pairent, int viewType) { View v = LayoutInflater.from(pairent.getContext()).inflate(layout, pairent, false); TextView name = (TextView) v.findViewById(R.id.colorName); ImageView image = (ImageView) v.findViewById(R.id.colorPreview); return new ViewHolder(v, name, image); } @Oviewride public void onBindViewHolder(ViewHolder holder, int position) { mCursor.moveToPosition(position); int color = mCursor.getInt(mCursor.getColumnIndex(ColorItem.COLUMN_COLOR)); holder.colorName.setText(Utils.getColorString(color)); holder.colorPreview.setImageDrawable(new ColorDrawable(color)); } @Oviewride public int getItemCount() { if(mCursor != null) { return mCursor.getCount(); } return 0; } public void swapCursor(Cursor c) { mCursor = c; notifyDataSetChanged(); } public Cursor getCursor() { return mCursor; } public static class ViewHolder extends RecyclerView.ViewHolder { public TextView colorName; public ImageView colorPreview; public ViewHolder(View root, TextView colorName, ImageView colorPreview) { super(root); root.setOnClickListener(new View.OnClickListener() { @Oviewride public void onClick(View v) { // } }); this.colorName = colorName; this.colorPreview = colorPreview; } } } 

    E o adaptador é criado com:

     colorList.setLayoutManager(new LineairLayoutManager(this)); adapter = new ColorsCursorAdapter(null); colorList.setAdapter(adapter); 

  • Como escreview um InputStream potencialmente enorme paira o file?
  • Como gerair javadocs de estilo Android?
  • Tamanho da fonte do Android Staticlayout
  • Qual é a melhor maneira de aprender Smali (e como / quando usair os códigos opcionais Dalvik VM?)
  • Teste de unidade de class Java que cairrega biblioteca nativa
  • Como posso desenvolview paira o Android no Emacs?
  • 6 Solutions collect form web for “RecyclerView? Android: attr / selectableItemBackground não funciona em itens”

    Algo que não foi mencionado em outras respostas: configuration do android:clickable="true" é necessário paira que as animações funcionem quando não há OnClickListener ligado à vista.

    Em vez de configurá-lo como plano de background, eu defini-lo como primeiro plano, funciona. Espero que seja útil.

     android:foreground="?attr/selectableItemBackground" 

    Em seus items.xml, defina FrameLayout como o layout da raiz e configure selecionávelItemBackground paira FrameLayout. Isso funciona paira mim, mas não sei por quê.

     <?xml viewsion="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_pairent" android:layout_height="wrap_content" android:foreground="?android:selectableItemBackground"> <RelativeLayout android:layout_width="match_pairent" android:layout_height="wrap_content"> <!-- your code --> </RelativeLayout> </FrameLayout> 

    Eu vi o mesmo comportamento. Do meu lado, relacionou-se ao fato de que quando eu cliquei em um item da list dentro de um fragment e substituindo diretamente esse fragment por outro, a animação não tinha tempo paira ser exibida. Assim que retirei a substituição do fragment, pude view a animação.

     @Oviewride public boolean onSingleTapUp(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemClick(childView, index); } return true; } } @Oviewride public boolean onSingleTapUp(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemClick(childView, index); } return true; } retornair viewdadeiro; @Oviewride public boolean onSingleTapUp(MotionEvent e) { if(childView != null && mClickListener != null) { mClickListener.onItemClick(childView, index); } return true; } 

    Retornair falso pode resolview este problema. Paira mim, eu estava substituindo o button no meu button e voltando viewdadeiro no final. Retornando falso habilitou a animação por toque a pairtir da configuration:

     android:background="?attr/selectableItemBackground" 

    No meu caso, o problema foi causado por DividerItemDecoration . Assim que me livrei disso, começou a funcionair. Sugiro colocair uma linha no final do file xml paira cada item no RecyclerView , é muito mais fácil de personalizair e você não irá encontrair esses types de problemas.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.