Ronnie
Ronnie

Reputation: 11198

Using an Intent in a list onItemClick

I am on my second activity (Main) like so:

Login -> Main -> Vforum

I managed to get to the Main activity using an Intent like so in the Login activity:

Intent logMeIn = new Intent(this,Main.class);
startActivity(logMeIn);

That works fine. My issue right now is going from Main to 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 is a ListView. Eclipse is saying:

The constructor Intent(new AdapterView.OnItemClickListener(){}, Class<Vforum>) is undefined

and I don't know what to put where this is to fix it. I just want to go to my third activity (Vforum).

Upvotes: 2

Views: 5979

Answers (2)

Tanmay Mandal
Tanmay Mandal

Reputation: 40168

projectList.setOnItemClickListener(new OnItemClickListener()
{
    public void onItemClick(AdapterView<?> parent, View view, int position, long id)
    {
        Intent launchVforum = new Intent(YourActivity.this, Vforum.class);
        startActivity(launchVforum);
    }
});

Upvotes: 3

Gligor
Gligor

Reputation: 2940

Yep. Have had similar issue once. My solution was to do the following (using your example):

-In your Main activity put a private context like so:

private Context mCtx;

-In your Main activity onCreate() method put this line somewhere:

mCtx = this;

-When creating the intent use mCtx instead of this:

Intent launchVforum = new Intent(mCtx, Vforum.class);

Upvotes: 9

Related Questions