[英]How do I interact with the AlertDialog View that is inside a Fragment from an Adapter inside an Adapter inside the AlertDialog?
标题几乎说明了一切。 我需要有关如何执行此操作的建议。 我可能只是将外部适配器添加为AlertDialog
上的一个View
,以使其变得不太复杂,但我仍然不知道如何从内部适配器与AlertDialog
交互。 我正在使用RecyclerView
。
这就是我的数据的样子。
"list_outer": [
{
"list_inner": [
]
}
]
例如,如果我从list_inner中选择某项,我想更新AlertDialog
的UI。
@Sreedev PR建议我使用要在适配器constructor
上传递的interface
。 问题在于,由于我尚未将外部适配器添加为View
,因此AlertDialog
目前还需要到达内部适配器,还需要执行另一步骤。 而且如果我将外部适配器只是一个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
并将其AlertDialog
Fragment
。
将AlertDialog
转换为Fragment
并应用@Sreedev PR的使用interface
的建议后,我能够使其工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.