The title almost says everything. I need suggestions on how can I do this. I might just add the outer adapter as a View
on the AlertDialog
to make it a little less complicated but I still don't know how can I interact with the AlertDialog
from the inner adapter. I'm using RecyclerView
.
This is how my data looks like.
"list_outer": [
{
"list_inner": [
]
}
]
For example, if I select something from list_inner, I want to update the UI of the AlertDialog
.
@Sreedev P R suggested that I use an interface
that is to be passed on the adapters constructor
. The problem is that there's another step before the AlertDialog
can reach the inner adapter, currently, because I haven't added the outer adapter as a View
yet. And if I do make the outer adapter just a View
, I still can't think of a clean way to pass that value to the AlertDialog
. Is it fine to reshow an AlertDialog
? Would it not create a memory leak? I might just do that if that's fine.
This is how my app is structured.
Fragment
|
AlertDialog
|
Adapter outer
|
Adapter inner
Adapter inner needs to be able to communicate or change the UI of AlertDialog
This the layout for the 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>
This is it's code.
View v = getLayoutInflater().inflate(R.layout.dialog, null);
lst.setLayoutManager(new LinearLayoutManager(ctx));
AdapterOuter adptr = new ModifierAdapter(ctx, arrayList);
lst.setAdapter(adptr);
UPDATE
To make it a little complicated, I ditch the AlertDialog
thing and made it a Fragment
.