Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在对话框中添加回收器视图_Android - Fatal编程技术网

Android 如何在对话框中添加回收器视图

Android 如何在对话框中添加回收器视图,android,Android,我试图在对话框中添加回收器视图,但对话框中没有显示任何内容…我在回收器视图中添加了卡片,希望在对话框中显示回收器视图 android.support.v7.app.AlertDialog.Builder dialog = new android.support.v7.app.AlertDialog.Builder(getContext()); LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Co

我试图在对话框中添加回收器视图,但对话框中没有显示任何内容…我在回收器视图中添加了卡片,希望在对话框中显示回收器视图

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);

您可以创建一个包含
RecyclerView
的布局,然后在对话框中进行设置:

Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.your_layout);
RecyclerView recyclerView = (RecyclerView) dialog.findViewById(your recycler);

您应该使用
LayoutManager
,因为它负责测量和定位
RecyclerView

中的项目视图,假设
R.layout.dialog\u 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);
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>

@样式/对话框动画
@动画/向上滑动对话框
@动画/幻灯片向下\u对话框
试试这个:

            val dialogBuilder = AlertDialog.Builder(this@MainActivity)
            val rcvDialog = RecyclerView(this@MainActivity)

            rcvDialog.adapter = DialogAdapter(ArrayList<Item>) //DialogAdapter create by your self
            rcvDialog.layoutManager = LinearLayoutManager(this@MainActivity)
            dialogBuilder.setView(rcvDialog)

            val dialog: Dialog = dialogBuilder.create()
            dialog.show()
val dialogBuilder=AlertDialog.Builder(this@MainActivity)
val rcvDialog=RecyclerView(this@MainActivity)
rcvDialog.adapter=DialogAdapter(ArrayList)//DialogAdapter由您自己创建
rcvDialog.layoutManager=LinearLayoutManager(this@MainActivity)
dialogBuilder.setView(rcvDialog)
val dialog:dialog=dialogBuilder.create()
dialog.show()

recyclerView中的setAdapter()无法应用于LastTransactionAdapterclass@suraj什么是LastTransactionAdapter类?在textview上设置数据,这些textview被添加到cardview上
            val dialogBuilder = AlertDialog.Builder(this@MainActivity)
            val rcvDialog = RecyclerView(this@MainActivity)

            rcvDialog.adapter = DialogAdapter(ArrayList<Item>) //DialogAdapter create by your self
            rcvDialog.layoutManager = LinearLayoutManager(this@MainActivity)
            dialogBuilder.setView(rcvDialog)

            val dialog: Dialog = dialogBuilder.create()
            dialog.show()