Android:在适配器上打开对话框 [英] Android: open dialog on adapter

查看:289
本文介绍了Android:在适配器上打开对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在RecyclerView Adapter内打开DialogFragment,或者如何通过主要活动来做到这一点?我需要通过单击添加到RecyclerView中的每个视图来打开它.

How do I open a DialogFragment inside a RecyclerView Adapter, or how do I do it through the main activity? I need to open it by clicking on every view that is added into the RecyclerView.

推荐答案

在DialogFragment上进行设置:

 public static myFragment newInstance() {
    return new myFragment();
}

在适配器上进行设置:

public Activity mcontext;

public SubjectsAdapter(Activity context) {
// Here we're getting the activity's context, 
// by setting the adapter on the activity with (this)   
this.mcontext=context;

}

通过适配器将其显示如下:

 myFragment newFragment = myFragment.newInstance();
 newFragment.show(mcontext.getFragmentManager(), "Title");

这篇关于Android:在适配器上打开对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆