首页 > 解决方案 > 在适配器类方法android中启动另一个活动

问题描述

这是我的自定义适配器类中的一种方法,

@Override
public Object instantiateItem(ViewGroup container, final int position) {

    layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = layoutInflater.inflate(R.layout.custom_layout, null);
    ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
    imageView.setImageResource(images[position]);

    if((position) == (images.length-1)){
        // Start another activity using intent
    }

    ViewPager vp = (ViewPager) container;
    vp.addView(view, 0);
    return view;
}

以及如何在这个自定义适配器类方法中启动新活动?

标签: androidandroid-intentandroid-activityandroid-adapter

解决方案


要开始另一个活动,您只需要一个上下文

Intent intent = new Intent(ctx, YourNewActivity.class)
ctx.startActivity(intent);

推荐阅读