I am trying to change background of selected files and folders on long click in recycler view. It is working for all kinds of files except video and image files. How can I fix that ?
MyRecyclerViewAdapter.java : (ViewHolder is an inner class)
// stores and recycles views as they are scrolled off screen
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener, View.OnLongClickListener {
TextView myTextView;
ImageButton myImage;
ViewHolder(View itemView) {
super(itemView);
myImage = (ImageButton) itemView.findViewById(R.id.buttonimage);
myTextView = (TextView) itemView.findViewById(R.id.info_text);
myImage.setOnClickListener(this);
myImage.setOnLongClickListener(this);
}
@Override
public void onClick(View view) {
if (mClickListener != null) mClickListener.onItemClick(view, getAdapterPosition());
}
@Override
public boolean onLongClick(View view) {
if (mClickListener != null) mClickListener.onLongClick(view, getAdapterPosition());
view.setBackgroundColor(Color.MAGENTA); //changing background color here
return true;
}
}
// convenience method for getting data at click position
public String getItem(int id) {
return mData2.get(id);
}
// allows clicks events to be caught
public void setClickListener(ItemClickListener itemClickListener) {
this.mClickListener = itemClickListener;
}
// allows clicks events to be caught
public void setLongClickListener(ItemClickListener itemClickListener1) {
this.mClickListener = itemClickListener1;
}
// parent activity will implement this method to respond to click events
public interface ItemClickListener {
void onItemClick(View view, int position);
boolean onLongClick(View view,int position);
}
}
MainActivity :
@Override
public boolean onLongClick(View view, int position) {
Toast.makeText(this, "is selected", Toast.LENGTH_SHORT)
.show();
return true;
}
activity_internal_storage.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.dell_1.myapp3.InternalStorage">
<android.support.v7.widget.RecyclerView
android:id="@+id/rvNumbers"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
recyclerview_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content"
>
<ImageButton
android:id="@+id/buttonimage"
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/folder"
android:scaleType="fitXY"
android:background="?android:selectableItemBackground"
/>
<TextView
android:id="@+id/info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:ellipsize="end"
android:maxLines="2"
/>
</LinearLayout>
Screenshots are selected but background color is not changing. AMCAT computer programming is an mp4 file , no background color change for it too.