我试图触发Carousel的点击。我希望如果我按下前进按钮,它会自动触发旋转木马上的点击,然后向前移动。手动单击(物理触摸)正在运行,但performClick()不起作用。代码如下
//************* Forward Button: Select Objects *************
Button forwardButton = (Button)this.findViewById(R.id.ForwardButton);
forwardButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(NewFieldTrip.this, SelectObjects.class);
//ImagePosition = (int)carousel.getSelectedItemId();
carousel.performClick();
i.putExtra("SelectedScene",ImagePosition);
startActivity(i);
}
});
carousel.setOnItemClickListener(new CarouselAdapter.OnItemClickListener(){
@Override
public void onItemClick(CarouselAdapter<?> parent, View view,
int position, long id) {
Toast.makeText(NewFieldTrip.this, "Select Position=" + position, Toast.LENGTH_SHORT).show();
ImagePosition = position;
}
});
伸出援助之手会很棒:)。
编辑:
public void scrollToChild(int i){
CarouselImageView view = (CarouselImageView)getAdapter().getView(i, null, null);
float angle = view.getCurrentAngle();
if(angle == 0)
return;
if(angle > 180.0f)
angle = 360.0f - angle;
else
angle = -angle;
mFlingRunnable.startUsingDistance(-angle);
}
答案 0 :(得分:2)
carousel 的类型是什么?的ListView?
因此,如果轮播是ListView,那么您在ListView点击时会发生什么事件?
performClick()触发 OnClickListener ,您未将其设置为 cantrousel 。您设置 OnItemClickListener ,因此您必须调用 performItemClick(...)。试试吧。
<强> UPD:强>
尝试做下面的事情:
1)制作方法 Carousel.scrollToChild(int i) public
2)
int itemCount = carousel.getAdapter().getCount();
int item = new Random().nextInt(itemCount);
View view - carousel.getAdapter().getView(item, null, null);
int itemId = carousel.getAdapter().getItemId(item);
carousel.scrollToChild(item);
carousel.performItemClick(view, item, itemId);