Solution 1 :
OOhhh I fixed it with
new Handler().post(new Runnable() {
@Override
public void run() {
addCategories(response);
}
});
Problem :
I have Array list with some values ( Movies categories list ).
I’m trying to add the to ChipGroup programatically, but the are not added.
Look on this method.
private void addCategories(MovieDetailsResponse response) {
ChipGroup chipGroup = mView.findViewById(R.id.categoriesChipGroup);
for (int i = 0; i < response.getGenres().size()-1; i++) {
Chip chip = new Chip(chipGroup.getContext());
chip.setText(response.getGenres().get(i).getName());
chipGroup.addView(chip);
}
}
When I debugging this method, so the genres size return me > 0 size ( array have genres ).
But when the debug comes to line Chip chip = new Chip(chipGroup.getContext());
The chips are not added and it’s throw an Exception :
public final class LambdaObserver<T> extends AtomicReference<Disposable>
implements Observer<T>, Disposable, LambdaConsumerIntrospection {
@Override
public void onNext(T t) {
if (!isDisposed()) {
try {
onNext.accept(t);
} catch (Throwable e) {
Exceptions.throwIfFatal(e);
get().dispose();
onError(e);
}
}
}
}
Here is my xml:
<com.google.android.material.chip.ChipGroup
android_layout_toEndOf="@id/movieDetailPosterContainer"
android_layout_marginStart="10dp"
android_id="@+id/categoriesChipGroup"
android_layout_width="match_parent"
android_layout_marginTop="10dp"
android_layout_below="@+id/tvMovieDetailsTitle"
android_layout_height="wrap_content">
</com.google.android.material.chip.ChipGroup>