标题几乎说明了一切。我需要关于如何做到这一点的建议。我可能只是将外部适配器添加为 aView以AlertDialog使其不那么复杂,但我仍然不知道如何与AlertDialog内部适配器进行交互。我正在使用RecyclerView.
这就是我的数据的样子。
"list_outer": [
{
"list_inner": [
]
}
]
例如,如果我从 list_inner 中选择一些东西,我想更新AlertDialog.
@Sreedev PR 建议我使用interface要在适配器上传递的constructor。问题是在到达内部适配器之前还有一个步骤AlertDialog,目前,因为我还没有添加外部适配器View。而且,如果我确实使外部适配器只是 a View,我仍然想不出一种干净的方法来将该值传递给AlertDialog. 重新显示一个AlertDialog好吗?它不会造成内存泄漏吗?如果没问题,我可能会这样做。
这就是我的应用程序的结构。
Fragment
|
AlertDialog
|
Adapter outer
|
Adapter inner
适配器内部需要能够通信或更改 AlertDialog 的 UI
这是AlertDialog.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:id="@+id/lytDlgAddItemToTicketMain"
android:focusableInTouchMode="true">
<android.support.constraint.Guideline
android:id="@+id/guideline5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_begin="16dp" />
<android.support.constraint.Guideline
android:id="@+id/guideline6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_end="16dp" />
<include
android:id="@+id/include3"
layout="@layout/dialog_header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v4.widget.NestedScrollView
android:layout_width="0dp"
android:layout_height="@dimen/DialogScrollViewHeight"
android:fillViewport="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/guideline6"
app:layout_constraintStart_toStartOf="@+id/guideline5"
app:layout_constraintTop_toBottomOf="@+id/include3">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/lstAddItemToTicketAddOns"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:listitem="@layout/adptr_modifier">
</android.support.v7.widget.RecyclerView>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.constraint.ConstraintLayout>
这是它的代码。
View v = getLayoutInflater().inflate(R.layout.dialog, null);
lst.setLayoutManager(new LinearLayoutManager(ctx));
AdapterOuter adptr = new ModifierAdapter(ctx, arrayList);
lst.setAdapter(adptr);
更新
为了让它有点复杂,我放弃了这个AlertDialog东西,把它变成了Fragment.