Change images dynamically
vangy1 opened this issue · 3 comments
vangy1 commented
Is there a way how to change images dynamically in the CarouselView on button click ? Let's say I'm on the second image and then I click on the button under the carousel and it changes all images to the other ones that I'll have in array of their IDs. It moves on to the first one as well.
sayyam commented
you can make multiple arrays of Id's and switch between them when you press
the button. Pick image id from switched array inside your imagelistener.
…On Thu, May 25, 2017 at 2:56 PM, Róbert Vangor ***@***.***> wrote:
Is there a way how to change images dynamically in the CarouselView on
button click ? Let's say I'm on second image and then I click on the button
under the carousel and it changes all images to the other ones that I'll
have in array of their IDs. It moves on to the first one as well.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#68>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAk1-e_-f-OQ-bFfwNUExue1wgAtdjD7ks5r9VBbgaJpZM4NmMOe>
.
--
Best Regards,
Sayyam Mehmood | Mobile Application Developer
Mobile | +923344298234
Skype | sayyam.mehmood
vangy1 commented
I tried that and it doesn't work. @sayyam
int[] redImages = {R.drawable.red1, R.drawable.red2};
int[] blackImages = {R.drawable.black1, R.drawable.black2};
carouselView = (CarouselView) findViewById(R.id.carouselView);
carouselView.setPageCount(2);
carouselView.setImageListener(blackListener);
black = findViewById(R.id.blackColor);
red = findViewById(R.id.redColor);
black.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
carouselView.setImageListener(blackListener);
}
});
red.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
carouselView.setImageListener(redListener);
}
});
ImageListener blackListener = new ImageListener() {
@Override
public void setImageForPosition(int position, ImageView imageView) {
imageView.setImageResource(blackImages[position]);
}
};
ImageListener redListener = new ImageListener() {
@Override
public void setImageForPosition(int position, ImageView imageView) {
imageView.setImageResource(redImages[position]);
}
};
vangy1 commented
Ok I found a solution. Each time you set Image listener, you have to do a setPageCount() as well. That would be
red.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
carouselView.setImageListener(redListener);
carouselView.setPageCount(numberOfImages);
}
});