0

I've never worked with dialogs before. What I currently have is json data loading in to a new activity from a RecyclerView list. I've managed to get the dialog to load on click, but without the data. Im not sure how to go about changing my Intent to load the new activity to loading the data in to the dialog.

My Previous onClick with the Intent.

public void onClick(View view) {
                //Toast.makeText(context, "Clicked", Toast.LENGTH_SHORT).show();

                Intent intent = new Intent(context,DetailActivity.class);
                intent.putExtra("url",dataMembers.posturl);
                RestActivity.tContent = dataMembers.posturl;
                context.startActivity(intent);
            }

This is with the dialog, it opens but its blank. I'm not sure where or how I would add my Intent to get the data in to the dialog.

public void onClick(View view) {
                //Toast.makeText(context, "Clicked", Toast.LENGTH_SHORT).show();

                DisplayMetrics metrics = context.getResources().getDisplayMetrics();

                int DeviceTotalWidth = metrics.widthPixels;
                int DeviceTotalHeight = metrics.heightPixels;

                final Dialog dialog = new Dialog(context);
                dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                dialog.setContentView(R.layout.activity_detail);
                dialog.getWindow().setLayout(DeviceTotalWidth ,DeviceTotalHeight);
                dialog.show();


                Intent intent = new Intent(context,DetailActivity.class);
                intent.putExtra("url",dataMembers.posturl);
                RestActivity.tContent = dataMembers.posturl;
                context.startActivity(intent);
            }
ValhallaSkies
  • 61
  • 1
  • 12

1 Answers1

0

You can launch an activity as a dialog using correct theme. See theme definition example below. Unless it is a simple yes/no dialog it is recommended to use DialogFragment. See discussion on DialogFragment vs Dialog

<style name="CompatDialogTheme" parent="@style/Theme.AppCompat.Dialog"> <item name="android:windowActionBar">false</item> <item name="windowNoTitle">true</item> </style>

dipu
  • 1,340
  • 3
  • 16
  • 28