我想ViewPager
刷卡基於其indicator
點擊。我已經使用傑克華頓的library爲ViewPager indicator
,但我沒有罰款根據我的要求任何適當的解決方案。我在這個網站上看到很多關於這個問題的問題,但沒有得到任何適當的解決方案任何人都可以幫我通過點擊indicator
view pager
應該如何獲得這樣的功能應該刷卡。在我的MainActivity.class下面如何獲取ViewPager指標OnClick在Android中
public class MainActivity extends AppCompatActivity {
private ViewPager viewPager;
private ViewPagerAdapter adapter;
private ArrayList<Integer> alPhoto;
private CirclePageIndicator mIndicator;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
loadArrayList();
// Locate the ViewPager in viewpager_main.xml
viewPager = (ViewPager) findViewById(R.id.pager);
adapter = new ViewPagerAdapter(MainActivity.this,alPhoto);
viewPager.setAdapter(adapter);
// Set for ViewPager indicator.
mIndicator = (CirclePageIndicator)findViewById(R.id.indicator);
mIndicator.setViewPager(viewPager);
mIndicator.setSnap(true);
}
private void loadArrayList() {
try {
alPhoto = new ArrayList<>();
alPhoto.add(R.drawable.first);
alPhoto.add(R.drawable.second);
alPhoto.add(R.drawable.third);
} catch (Exception e) {
e.printStackTrace();
}
}
}
這是我的適配器。
public class ViewPagerAdapter extends PagerAdapter {
private Context context;
private ArrayList<Integer> alPhoto;
private LayoutInflater inflater;
public ViewPagerAdapter(Context mainActivity,ArrayList<Integer> alPhoto) {
this.context= mainActivity;
this.alPhoto=alPhoto;
}
@Override
public int getCount() {
return alPhoto.size();
}
@Override
public boolean isViewFromObject(View view, Object object) {
return view == ((RelativeLayout) object);
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
ImageView imgflag;
inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View itemView = inflater.inflate(R.layout.viewpager_item, container,false);
imgflag = (ImageView) itemView.findViewById(R.id.flag);
imgflag.setImageResource(alPhoto.get(position));
((ViewPager) container).addView(itemView);
return itemView;
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
// Remove viewpager_item.xml from ViewPager
((ViewPager) container).removeView((RelativeLayout) object);
}
}
嗨Sakib只設置的onclick –