我正在尝试将onItemClickListener添加到我的ListView
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
答案 0 :(得分:2)
this
类型为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);
}
});
...
}