I have the following xml:

<ImageView android:id="@+id/iv_upload" android:layout_width="@dimen/_80sdp" android:layout_height="@dimen/_80sdp" android:src="@drawable/disable_info" /> <ImageView android:id="@+id/photo_close_btn" android:layout_width="@dimen/_15sdp" android:layout_height="@dimen/_15sdp" android:src="@drawable/close_btn" /> <md.simpals.md999.views.ProgressWheel android:id="@+id/loader_photo" android:layout_width="@dimen/size_progress_small" android:layout_height="@dimen/size_progress_small" android:layout_centerHorizontal="true" android:layout_centerVertical="true" custom:matProg_barColor="@color/progress_bar" custom:matProg_progressIndeterminate="true" /> 

In the fragment code I need to process the click on photo_close_btn (by type as written below by Sergey Gornostaev):

 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.my_fragment, container, false); ImageView imageView = (ImageView) v.findViewById(R.id.photo_close_btn); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // РСакция Π½Π° ΠΊΠ»ΠΈΠΊ } }); } 

The only thing I need to pass this // Reaction to a click in the Gridview .Holder, tried to write something similar (should delete an element when clicking on photo_close_btn):

  class UploadHolder { @Bind(R.id.photo_close_btn) ImageView photoClose; public UploadHolder(View view) { ButterKnife.bind(this, view); } @OnClick(R.id.iv_upload) void clickImage() { } } 

    1 answer 1

    What's the problem? In the onCreateView fragment, assign a handler for photo_close_btn :

     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.my_fragment, container, false); ImageView imageView = (ImageView) v.findViewById(R.id.photo_close_btn); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // РСакция Π½Π° ΠΊΠ»ΠΈΠΊ } }); } 
    • super and in // Reaction to a click - is this appropriate? controls.remove (getAdapterPosition ()). getImageUploads (). get (position); since delete by clicking on a click, it must delete. - Inkognito
    • one
      Judging by the getAdapterPosition() method of the RecyclerView.ViewHolder class, the layout given in the question is the layout of the RecyclerView element. So? - Sergey Gornostaev
    • Yes everything is correct. - Inkognito
    • one
      Then it is better to transfer the installation of the handler to the ViewHolder constructor. - Sergey Gornostaev
    • about the following? class Buttons extends RecyclerView.ViewHolder {@Bind (R.id.photo_close_btn) LinearLayout mCloseButton; @OnClick (R.id.photo_close_btn) public void clickCancel (View view) {if (itemClick! = Null) itemClick.clickCancel (getAdapterPosition ()). GetImageUploads (). Get (position)); } something namudril ...) well the right direction?) - Inkognito