I am working on a project in which I have created a Carousel using this library.
I also want to show the Image Description in a TextView which should change as the image changes. I am unable to change the TextView as the image changes. What should I do to make this happen?
My Java Code:
public class Carousel extends AppCompatActivity {
CarouselView carouselView;
int[] sampleImages = {R.drawable.a,R.drawable.b,R.drawable.c,R.drawable.d};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about_devs);
carouselView = findViewById(R.id.carouselView);
carouselView.setPageCount(sampleImages.length);
carouselView.setImageListener(imageListener);
}
ImageListener imageListener = (position, imageView) -> imageView.setImageResource(sampleImages[position]);
My XML Code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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="match_parent"
android:background="@color/retro_red"
tools:context=".AboutDevs">
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="@font/pragya"
android:text="@string/about_devs"
android:textColor="@color/white"
android:textSize="28sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.074" />
<com.synnapps.carouselview.CarouselView
android:id="@+id/carouselView"
android:layout_width="400dp"
android:layout_height="450dp"
android:layout_marginTop="28dp"
android:layout_marginEnd="4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView5"
app:layout_constraintVertical_bias="0.235" />
</androidx.constraintlayout.widget.ConstraintLayout>
I know this might be a silly thing to ask but I am unable to figure it out. I would appreciate any help.