android - 在适配器类方法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;
}
以及如何在这个自定义适配器类方法中启动新活动?
解决方案
要开始另一个活动,您只需要一个上下文
Intent intent = new Intent(ctx, YourNewActivity.class)
ctx.startActivity(intent);
推荐阅读
- postgresql - postgres typeorm 返回直到列的总和大于条件
- swift - 将变量从函数传递到视图
- swift - 如何使用 MVC 正确清理我的代码?
- c - C函数错误:中止函数还是简单地退出程序更好?
- r - 用多列重塑数据
- rest - 通过 REST API 检测任务何时完成
- angular - ngx-translate fails to resolve translations when running Jasmine/Karma tests
- python - 如何让我的不和谐机器人每隔几秒发送一次消息?(discord.py)
- c++ - 结构化模板参数
- synchronization - 尝试列出给定 servicePrincipals ID 的现有同步作业时出现 UnknownError