I have RecyclerView
.The element at position is 0 is header for EditText
,then all other elements are images.On long pressing on EditText
it gives option paste.This works fine.
But when I scroll the recycler view to the bottom and again come to top and long press it will not show the paste option and gives error .
On Scrolling to the bottom and again coming to top passes call to onBindViewHolder
.
TextView
: TextView
does not support text selection. Selection cancelled.
public class Someclass extends RecyclerView.Adapter<RecyclerView.ViewHolder> implements View.OnClickListener {
private static final int TYPE_EDIT = 0;
private static final int TYPE_IMAGE = 1;
List<String> msomelist = new ArrayList<String>();
public void someMethod(List<String> somelist) {
msomelist.clear();
msomelist.addAll(somelist);
notifyDataSetChanged();
}
public Someclass(Activity activity, List<String> somelist) {
this.activity = activity;
this.msomelist.clear();
this.msomelist.addAll(somelist);
mContext = activity;
}
@Override
public int getItemViewType(int position) {
if (position == 0)
return TYPE_EDIT;
return TYPE_IMAGE;
}
@Override
public void onClick(View view) {
int postition = (int) view.getTag();
msomelist.remove(postition);
notifyDataSetChanged();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
ImageView img;
public ViewHolder(View itemView) {
super(itemView);
img = (ImageView) itemView.findViewById(R.id.image);
}
}
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
if (viewType == TYPE_IMAGE) {
View view = LayoutInflater.from(mContext)
.inflate(somelayout, false);
ViewHolder holder = new ViewHolder(view);
return holder;
} else {
View view = LayoutInflater.from(mContext)
.inflate(someotherlayout, false);
return new OtherHolder(view);
}
}
class OtherHolder extends RecyclerView.ViewHolder {
EditText editText;
public OtherHolder(View itemView) {
super(itemView);
editText = (EditText) itemView.findViewById(R.id.ediItext);
editText.requestFocus();
}
}
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
if (holder instanceof ViewHolder) {
some function.....
} else if (holder instanceof OtherHolder) {
some function
}
}
}