Chip wan't add to ChipGroup programmatically
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>
OOhhh I fixed it with
new Handler().post(new Runnable() { @Override public void run() { addCategories(response); } });