Reputation: 55
Here's my code
this.getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Intent i = new Intent(this,lastview.class);
startActivity(i);
}
});
the "this" is a ListActivity,but I want the next activity is a normal activity
and my code is wrong in this line
Intent i = new Intent(this,lastview.class);
the wrong message is
The constructor Intent(new AdapterView.OnItemClickListener(){}, Class<lastview>) is undefined
how can I fix it ?
Upvotes: 0
Views: 932
Reputation: 22493
change this line
Intent i = new Intent(this,lastview.class);
like this, change your activity to MyListActivity
Intent i = new Intent( MyListActivity.this, lastview.class);
Upvotes: 1
Reputation: 1217
Here is the sample code .This will help you.
public class YourListActivity extends ListActivity {
private Context context;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
context =this;
.....
......
this.getListView().setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
Intent i = new Intent(context,lastview.class);
// else you can use the code like below
//Intent i = new Intent(YourListActivity.this ,lastview.class);
startActivity(i);
}
});
}
Upvotes: 0
Reputation: 1641
You can also write it like :
startActivity(new Intent(Yourclass_name.this,lastview.class));
Upvotes: 0