单击第1项时的Android CarouselPicker [英] Android CarouselPicker when 1st item is click
问题描述
我在github上发现了一个包含CarouselPicker的文库 com.github.Vatican-Cameos:CarouselPicker:v1.0 我在依赖项中添加了这个,并在存储库中编译 maven {url' https://jitpack.io '}
I found a library on github that has CarouselPicker com.github.Vatican-Cameos:CarouselPicker:v1.0 i added this in the dependencies and compile also in repositories maven { url 'https://jitpack.io'}
我已成功制作CarouselPicker,这是 JAVA CODE
I have successfully make a CarouselPicker this is the JAVA CODE
carouselPicker = (CarouselPicker)findViewById(R.id.carouselPicker);
List<CarouselPicker.PickerItem> itemsImage = new ArrayList<>();
itemsImage.add(new CarouselPicker.DrawableItem(R.drawable.abc));
itemsImage.add(new CarouselPicker.DrawableItem(R.drawable.123));
itemsImage.add(new CarouselPicker.DrawableItem(R.drawable.colors));
itemsImage.add(new CarouselPicker.DrawableItem(R.drawable.shapes));
CarouselPicker.CarouselViewAdapter imageAdapter = new CarouselPicker.CarouselViewAdapter(this, itemsImage,0);
carouselPicker.setAdapter(imageAdapter);
通过拥有LinearLayout,这是XML代码
And by having a LinearLayout this is the XML code
<in.goodiebag.carouselpicker.CarouselPicker
android:id="@+id/carouselPicker"
android:layout_marginTop="50dp"
android:layout_marginBottom="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:items_visible="three"
/>
我无法在google上找到如果旋转木马选择器中的第一项选择如 OnClickListener
更改意图
I cant find on google on what if the 1st item in the carousel picker selected like a OnClickListener
to change the intent
推荐答案
我找到了您在此链接上使用的库
您必须使用 addOnPageChangeListener
像这样:
I found a library you used on this link
You must use addOnPageChangeListener
like this:
carouselPicker.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
@Override
public void onPageSelected(int position) {
//position of the selected item
if(position == 0){
startActivity(new Intent(thisActivity.this, anotherActivity1.class));
}
else if(position == 1){
startActivity(new Intent(thisActivity.this, anotherActivity2.class));
}
// Same conditions for another cases.
}
@Override
public void onPageScrollStateChanged(int state) {
}
});
那么,你想要的 onClickListener
处理click事件, onPageSelected
方法。
So, your onClickListener
that you want to handle the click event, is onPageSelected
method.
这篇关于单击第1项时的Android CarouselPicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!