在Android中使用View Pager指示器查看寻呼机点击事件?

时间:2014-12-02 04:54:41

标签: android slider android-viewpager viewpagerindicator viewpage

我正在使用this sample code and library。这个库工作正常,可以滑动屏幕,但我想点击查看寻呼机指示器滑块工作到该位置。

注意:

此View寻呼机指示灯点击在Android手机主页中正常工作。

1 个答案:

答案 0 :(得分:0)

你必须在viewPager的视图上设置它,就像这样,

public class ViewPagerAdapter extends PagerAdapter {

Context context;
String[] title;
String[] image;
LayoutInflater inflater;
ArrayList<Categories> arrayList;

Activity activity;

public ViewPagerAdapter(Context context, ArrayList<Categories> arrayList) {
    this.context = context;
    this.arrayList = arrayList;
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return arrayList.size();
}

@Override
public boolean isViewFromObject(View view, Object object) {
    // TODO Auto-generated method stub
    return view == ((RelativeLayout) object);
}

@Override
public Object instantiateItem(ViewGroup container, final int position) {
    // TODO Auto-generated method stub

    TextView txtTitle;
    ImageView image;

    inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View itemView = inflater.inflate(R.layout.item, container, false);

    itemView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent i = new Intent(context, ListViewActivity.class);
            Bundle b = new Bundle();
            final String id = arrayList.get(position).getId();
            b.putString("id", id);
            i.putExtras(b);
            context.startActivity(i);
        }
    });

    txtTitle = (TextView) itemView.findViewById(R.id.tvName);
    image = (ImageView) itemView.findViewById(R.id.imageView1);

    txtTitle.setText(arrayList.get(position).getTitle());
    ((ViewPager) container).addView(itemView);

    Ion.with(context).load(arrayList.get(position).getImage()).withBitmap()
            .resize(512, 512).centerCrop().intoImageView(image);

    return itemView;
}

@Override
public void destroyItem(View container, int position, Object object) {
    ((ViewPager) container).removeView((View) object);
}
}

试试这个......它适合我。