bbbbbird1
bbbbbird1

Reputation: 55

After ListView onClick,change activity

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

Answers (3)

RajaReddy PolamReddy
RajaReddy PolamReddy

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

Finder
Finder

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

deepak Sharma
deepak Sharma

Reputation: 1641

You can also write it like :

startActivity(new Intent(Yourclass_name.this,lastview.class));  

Upvotes: 0

Related Questions