2016-11-12 85 views
1

林回收视图试图在对话,但对话框不显示任何添加回收看法......我增加了关于回收视图卡和要显示在对话框如何添加在对话框

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

回答

0

可以回收视图创建一个布局包含RecyclerView然后将其设置对话框:

Dialog dialog = new Dialog(context); 
dialog.setContentView(R.layout.your_layout); 
RecyclerView recyclerView = (RecyclerView) dialog.findViewById(your recycler); 
0
TransactionReportCardAdapter adapter = new TransactionReportCardAdapter(listTransactionDetails, context); 
adapter.setAdapter(themeAdapter); 
recyclerView.setHasFixedSize(true); 
recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false)); 

你应该使用LayoutManager因为它负责测量与定位项意见在RecyclerView

3

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

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> 
+0

setAdapter(不能应用于LastTransactionsAdapter类 –

+0

@suraj什么是LastTransactionsAdapter类? –

+0

在textview上设置数据,并将这些textview添加到cardview上 –

-1

试试:)中recyclerView

  val dialogBuilder = AlertDialog.Builder([email protected]) 
      val rcvDialog = RecyclerView([email protected]) 

      rcvDialog.adapter = DialogAdapter(ArrayList<Item>) //DialogAdapter create by your self 
      rcvDialog.layoutManager = LinearLayoutManager([email protected]) 
      dialogBuilder.setView(rcvDialog) 

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