gpt4 book ai didi

java - 创建 onItemClickListener 时出现问题

转载 作者:行者123 更新时间:2023-12-02 08:19:12 24 4
gpt4 key购买 nike

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

最佳答案

annonymos 类中的

this 类型为 AdapterView.OnItemClickListener,使用 YOURACTIVITYNAME.this 来引用 Activity 。

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

关于java - 创建 onItemClickListener 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5784039/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com