2011-04-25 67 views
0

我想一個onItemClickListener添加到我的ListView問題創造onItemClickListener

streamListView.setAdapter(this.streamAdapter); 
      this.streamListView.setOnItemClickListener(new OnItemClickListener() { 
       @Override 
       public void onItemClick(AdapterView<?> a, View v, int position, long id) { 
        Intent intent = new Intent(this, MessageDetailActivity.class); 
        startActivity(intent); 
       } 
      }); 

,但我得到的錯誤:

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

回答

2

this的annonymos類是類型AdapterView.OnItemClickListener使用YOURACTIVITYNAME.this指內活動。

public class MyActivity extends Activity { 
.... 
streamListView.setAdapter(this.streamAdapter); 
    this.streamListView.setOnItemClickListener(new OnItemClickListener() { 
     @Override 
      public void onItemClick(AdapterView<?> a, View v, int position, long id) { 
>>>>>  Intent intent = new Intent(MyActivity.this, MessageDetailActivity.class); 
       startActivity(intent); 
      } 
    }); 
... 
}