创建onItemClickListener时出现问题

时间:2011-04-25 22:36:58

标签: java android listview listadapter onitemclicklistener

我正在尝试将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

1 个答案:

答案 0 :(得分:2)

annonymos类中的

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);
            }
     });
...
}