Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add recycler view on dialog

Tags:

android

Im trying to add recycler view on dialog but dialog not showing anything...I have added cards on recycler view and want to display recycler view on dialog

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);
like image 611
suraj shinde Avatar asked Dec 06 '22 16:12

suraj shinde


1 Answers

Assuming R.layout.dialog_layout is a layout with 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);

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>
like image 118
Android Developer Avatar answered Dec 29 '22 11:12

Android Developer