Maheswaran Ravisankar Maheswaran Ravisankar - 1 year ago 97
Android Question

Add RecyclerView(RecyclerFragment) to a Dialog

I have my custom RecyclerView to create a ListView.
And it works great, when I am trying to populate a list view in my layout's id.

FragmentTransaction ft = getFragmentManager().beginTransaction();
Bundle bundle = new Bundle();
bundle.putBoolean("enablePullToRefresh", false);
GridValues gridValues = new GridValues();
gridValues.rowViewLayout = R.layout.my_detail_row_view;

gridValues.delegate = this;

mygrid = new CustomGridView(gridValues, bundle);
mygrid.showAsGrid = true;
mygrid.spanCount = 2;
mygrid.layoutOrientation = LinearLayoutManager.VERTICAL;
mygrid.noRowColor = true;
mygrid.gridName = "mygrid";

ft.replace(, mygrid);

Now, I would like to populate a new list inside a dialog.
How can I do that?

I tried this, Having mygrid as static

public static class MyDialogFragment extends DialogFragment {
static MyDialogFragment newInstance() {
return new MyDialogFragment();

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return mygrid.getView();

And then,

FragmentTransaction ft = getFragmentManager().beginTransaction();
DialogFragment newFragment = MyDialogFragment.newInstance();
ft.add(, newFragment);

r7v r7v
Answer Source

DialogFragment is just another Fragment, Inflate your custom view like you would do for any other fragment.

public class MyDialogFragment extends DialogFragment {
    private RecyclerView mRecyclerView;
    private MyRecyclerAdapter adapter;
    // this method create view for your Dialog
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
          //inflate layout with recycler view
         View v = inflater.inflate(R.layout.fragment_dialog, container, false);
        mRecyclerView = (RecyclerView) v.findViewById(;
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        CustomAdapter adapter = new MyRecyclerAdapter(context, customList);
         //get your recycler view and populate it.
         return v;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download