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

Posted

技术标签:

【中文标题】使用 View Pager 指示器单击事件在 android 中查看寻呼机?【英文标题】:View Pager in android with View Pager indicator Click Event? 【发布时间】:2014-12-02 04:54:40 【问题描述】:

我正在使用this sample code and library。这个库在滑动屏幕时运行良好,但我希望在单击查看寻呼机指示器幻灯片时为该位置工作。

注意:

此查看寻呼机指示器点击在 android 手机主页中工作。

【问题讨论】:

已经提到:如果您在视图寻呼机中使用 OnPageChangeListener,您应该在指示器中设置它,而不是直接在寻呼机上:titleIndicator.setOnPageChangeListener(mPageChangeListener); 你可以参考我的示例代码吗 不需要第 3 方代码,也不需要任何类型的手动破解。 TabLayout 是构建页面指示器的完美小部件。您可以点击开箱即用的页面指示器。看看这个答案:***.com/a/44231881/1850606 【参考方案1】:

你必须在 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);


试试这个...它对我有用。

【讨论】:

以上是关于使用 View Pager 指示器单击事件在 android 中查看寻呼机?的主要内容,如果未能解决你的问题,请参考以下文章

列表 CellTable/ Pager 顶部的特定元素

如何在 View Pager 中使用滑动抽屉?

片段无法加载到 View_pager tabLayout [重复]

Drupal呈现视图页面从$view对象

Pager View Controller 的根视图的大小与后续 View Controller 的大小不同

无法更新 View Pager 中的中间片段。