0

friends I created an dialogfragment which consist of a recyclerview. in that recyclerview I added some image and text.when I select the particular image it should be selected means I want the position of that particulars get to my activity and dialog fragment is dismiss, I go through the various sited but didn't understand. can anyone please tell me,new to the programming.

Thanks in advance

sun
  • 1,202
  • 3
  • 14
  • 29
  • 1
    Find your answer [HERE](http://stackoverflow.com/questions/28296708/get-clicked-item-and-its-position-in-recyclerview) avoid posting duplicate questions. – Devendra Singh May 07 '16 at 07:58

1 Answers1

0

Create a method in your activity that shows the dialog fragment as below

public void onRecyclerItemSelected(int position){
    yourDialog.dismiss();
}

To call this method from your dialog fragment, capture click of recycler view using interface from adapter. So whenever recycler view is clicked you can call your activity method from dialog fragment using

if(getActivity()!=null && getActivity() instanceOf YourActivity){
    ((YourActivity)getActivity().onRecyclerItemSelected(pos);
}

Where pos is the int pos of recycler item clicked. Hope you understand. Any doubts please let me know.

Dhruv
  • 1,763
  • 1
  • 12
  • 25
Ragesh Ramesh
  • 3,232
  • 2
  • 12
  • 20
  • I didn't understand "capture click of recycler view using interface from adapter." can you please give some more info – sun May 07 '16 at 08:07
  • have a look at the link to know know how to have on item click listener. http://antonioleiva.com/recyclerview-listener/ – Ragesh Ramesh May 07 '16 at 09:49