如何在对话框上添加回收站视图

sur*_*nde 3 android

我正在尝试在对话框上添加回收站视图,但对话框未显示任何内容...我已在回收站视图上添加卡片,并想在对话框上显示回收站视图

android.support.v7.app.AlertDialog.Builder dialog = new android.support.v7.app.AlertDialog.Builder(getContext());
LayoutInflater inflater = (LayoutInflater)   getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dialogView = inflater.inflate(R.layout.last_transaction_report, null);
recyclerView = (RecyclerView) dialogView.findViewById(R.id.transactio_rep_recyclerView);
dialog.setView(dialogView);

AlertDialog alertDialog = dialog.create();
// alertDialog.setContentView(dialogView);
alertDialog.show();

adapter = new TransactionReportCardAdapter(listTransactionDetails, this);
recyclerView.setAdapter(adapter);
Run Code Online (Sandbox Code Playgroud)

And*_*per 7

假设R.layout.dialog_layout是带有recyclerview的布局

Dialog dialog = new Dialog(context, R.style.DialogSlideAnim);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
dialog.setContentView(R.layout.dialog_layout);
dialog.setCanceledOnTouchOutside(true);
dialog.setCancelable(true);
dialog.show();

RecyclerView rvTest = (RecyclerView) dialog.findViewById(R.id.rvTest);
rvTest.setHasFixedSize(true);
rvTest.setLayoutManager(new LinearLayoutManager(context));
rvTest.addItemDecoration(new SimpleDividerItemDecoration(context, R.drawable.divider));

DataDialogAdapter rvAdapter = new DataDialogAdapter(context, rvTestList);
rvTest.setAdapter(rvAdapter);
Run Code Online (Sandbox Code Playgroud)

styles.xml

<style name="DialogSlideAnim" parent="@android:style/Theme.Dialog">
    <item name="android:windowAnimationStyle">@style/DialogAnimation</item>
</style>
<style name="DialogAnimation">
    <item name="android:windowEnterAnimation">@anim/slide_up_dialog</item>
    <item name="android:windowExitAnimation">@anim/slide_down_dialog</item>
</style>
Run Code Online (Sandbox Code Playgroud)