如何与AlertDialog内的适配器内的适配器中的片段内的AlertDialog视图交互?

时间:2019-07-10 04:11:37

标签: java android android-recyclerview recycler-adapter

标题几乎说明了一切。我需要有关如何执行此操作的建议。我可能只是将外部适配器添加为View上的AlertDialog,以使其变得不太复杂,但我仍然不知道如何从内部适配器与AlertDialog进行交互。我正在使用RecyclerView

这就是我的数据。

"list_outer": [
  {
    "list_inner": [

    ]
  }
]

例如,如果我从list_inner中选择某项,我想更新AlertDialog的UI。

@Sreedev P R建议我使用将在适配器interface上传递的constructor。问题是,AlertDialog目前才能到达内部适配器,这还有另外一步,因为我还没有将外部适配器添加为View。而且,如果我确实将外部适配器设置为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

1 个答案:

答案 0 :(得分:0)

AlertDialog转换为Fragment并应用@Sreedev P R建议使用interface之后,我得以使其工作。