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).
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);
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);
}
});
精彩评论