android - 在列表 onItemClick 中使用 Intent

标签 android listview click android-intent

我的第二个 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/

相关文章:

android - 使用 ListView 自定义标题栏

android - 单击特定 View 时如何获取项目在 ListView 中的位置?

jquery - 使用 jQuery 定位特定的 href

c# - 在 Xamarin.Android 使用的 NuGet 包中包含 native 库

Android listview行删除动画

android - 像 IOS 一样在 ListView 中滑动显示按钮

javascript - 切换事件偶尔工作

Android Studio 在 Fedora 上崩溃

android - 在 Android 中使用反射时,我会受到不利影响吗?

javascript - 如何使用 webview 或 Web 浏览器在 android Studio 中显示 OKHTTP html 响应并与之交互