我已经创建了一个由多个项目(图像和文本)组成的水平滚动,但是如何为每个项目添加一个点击事件。
我已经按照本教程获得了现在的位置: https ://www.youtube.com/watch?v=sTJm1Ys9jMI
MainActivity.java:
CarouselPicker carouselPicker1, carouselPicker2, carouselPicker3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
carouselPicker1 = (CarouselPicker) findViewById(R.id.carouselPicker1);
carouselPicker2 = (CarouselPicker) findViewById(R.id.carouselPicker2);
carouselPicker3 = (CarouselPicker) findViewById(R.id.carouselPicker3);
//Carousel 1 with all images
List<CarouselPicker.PickerItem> itemsImages = new ArrayList<>();
itemsImages.add(new CarouselPicker.DrawableItem(R.mipmap.ic_launcher));
itemsImages.add(new CarouselPicker.DrawableItem(R.mipmap.ic_launcher_round));
itemsImages.add(new CarouselPicker.DrawableItem(R.mipmap.ic_launcher));
itemsImages.add(new CarouselPicker.DrawableItem(R.mipmap.ic_launcher));
itemsImages.add(new CarouselPicker.DrawableItem(R.mipmap.ic_launcher));
itemsImages.add(new CarouselPicker.DrawableItem(R.mipmap.ic_launcher));
itemsImages.add(new CarouselPicker.DrawableItem(R.mipmap.ic_launcher));
itemsImages.add(new CarouselPicker.DrawableItem(R.mipmap.ic_launcher));
itemsImages.add(new CarouselPicker.DrawableItem(R.mipmap.ic_launcher));
itemsImages.add(new CarouselPicker.DrawableItem(R.mipmap.ic_launcher));
itemsImages.add(new CarouselPicker.DrawableItem(R.mipmap.ic_launcher));
itemsImages.add(new CarouselPicker.DrawableItem(R.mipmap.ic_launcher));
itemsImages.add(new CarouselPicker.DrawableItem(R.mipmap.ic_launcher));
itemsImages.add(new CarouselPicker.DrawableItem(R.mipmap.ic_launcher));
CarouselPicker.CarouselViewAdapter imageAdapter = new CarouselPicker.CarouselViewAdapter(this, itemsImages, 0);
</LinearLayout>
如何为 MainActivy.java 中显示的每个图像添加按钮功能?
杨魅力
相关分类