ViewPager点击每一项设置的监听

ViewPager点击每一项时,不需要自定义ViewPager,然后写点击事件,简单一点,在ViewPager的适配器中instantiateItem实现即可,现在记录一下,以便日后忘记

@Override

public Object instantiateItem(View container, final int position) {
//点击ViewPager的每一项
View viewClick=list.get(position);
viewClick.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

// if(null!=onItemClickListener){
// onItemClickListener.onClick(position);
// }
// //跳转到详情界面
// Intent intent = new Intent(getActivity(), BabyActivity.class);
// startActivity(intent);
Toast.makeText(MainActivity.this,"点击了:"+position, 1).show();
}
});
((ViewPager)container).addView(list.get(position), 0);
return list.get(position);

你可能感兴趣的:(ViewPager点击每一项设置的监听)