我的第二个 Activity (主要)是这样的:
Login -> Main -> Vforum
我设法在登录 Activity 中使用 Intent 进入主要 Activity :
Intent logMeIn = new Intent(this,Main.class);
startActivity(logMeIn);
这很好用。我现在的问题是从 Main 转到 Vforum。
projectList.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
Intent launchVforum = new Intent(this, Vforum.class);
startActivity(launchVforum);
}
});
projectList
是一个 ListView
。 Eclipse 说:
The constructor Intent(new AdapterView.OnItemClickListener(){}, Class<Vforum>) is undefined
而且我不知道在 this
的地方放什么来修复它。我只想参加我的第三个 Activity (Vforum)。
最佳答案
是的。曾经有过类似的问题。我的解决方案是执行以下操作(使用您的示例):
-在您的主要 Activity 中放置一个私有(private)上下文,如下所示:
private Context mCtx;
-在您的主要 Activity onCreate() 方法中将此行放在某处:
mCtx = this;
-创建 Intent 时使用 mCtx 而不是这个:
Intent launchVforum = new Intent(mCtx, Vforum.class);
关于android - 在列表 onItemClick 中使用 Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5971817/