I tried as below at onClick() method of recyelerview.viewholder class.
SampleDialogFragment used in the sample extends DialogFragment.
@Override
public void onClick(View v)
{
SampleDialogFragment df= new SampleDialogFragment();
df.show(v.getContext().getSupportFragmentManager(), "Dialog");
}
I'm facing problem at v.getContext().getSupportFragmentManager()
. I can't call getSupportFragmentManager().
I also tried as below .
@Override
public void onClick(View v)
{
SampleDialogFragment df= new SampleDialogFragment();
SampleActivity activity = new SampleActivity();
df.show(activity.getSupportFragmentManager(), "Dialog");
}
SampleActivity is the activity the recycler view is attached . It shows no error. When I run the app and crash.
The log shows that the activity has destoryed.
Any solution ?
the easiest way i use it
in onClick
in your MainActivity or where u set your recycleview
The proper way is to use an interface.
And call the interface method when the onClick method is fired.
You have to pass the
OnItemClickListener
Interface instance fromSampleActivity
And have it implement it in your
SampleActivity