I am trying to develop an Android image flipper with the following behaviours.
- It automatically starts to flip when the activity starts (Flipping interval also has been implemented).
- Users also can slide images in the flipper right or left
- Users should be able to click a particular image and load another activity
Item 1, I could successfully implement without an issue.
The issue is, I cannot implement both 2 & 3 at once because of imageView.OnClickListner()
always comes first before firing the Flipper.OnTouch()
Listner. So, sliding never happens but new activity loads at once.
How can I implement all 3 requirements at once in my Android app?
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_home, container, false);
int sliderImgs[] = {R.drawable.slider_img_1, R.drawable.slider_img_1, R.drawable.slider_img_1};
viewFlipper = root.findViewById(R.id.img_slider);
mContext = this.getContext();
viewFlipper.setAutoStart(true);
viewFlipper.setFlipInterval(20000);
viewFlipper.setInAnimation(this.getContext(), R.anim.slide_in_right);
viewFlipper.setOutAnimation(this.getContext(), R.anim.slide_out_left);
viewFlipper.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(final View view, final MotionEvent event) {
detector.onTouchEvent(event);
return true;
}
});
for(int sliderImg:sliderImgs){
slideshowImages(sliderImg);
}
}
private void slideshowImages(int image){
ImageView imageView = new ImageView(this.getContext());
imageView.setBackgroundResource(image);
viewFlipper.addView(imageView);
imageView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
View notificaionFragment = getLayoutInflater().inflate(R.layout.fragment_property_details, null);
BottomSheetDialog bottomSheetDialog = arrangeBottomSheet(notificaionFragment);
new Notification(notificaionFragment, mContext, getLayoutInflater(), bottomSheetDialog);
}
});
}