android 列表视图可点击问题
我有这个定制清单。每行包含一个图像和两行文本,一行位于另一行下方。我想在单击任何列表项时打开一个新活动。但即使在实现 setOnItemClickListener() 之后我也无法这样做。如果我错了,请纠正我。以下是列表的代码。 PS:这是正常活动,并非列表活动。
l1.setAdapter(new EfficientAdapter(this,eventTitleArray,eventDateArray,eventImageLinkArray));
//l1 = getListView();
l1.setClickable(true);
l1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
Intent intent = new Intent(MainActivity.this, DisplayActivity.class);
Bundle b = new Bundle();
b.putString("event", eventTitleArray[position]);
intent.putExtras(bundle);
startActivity(intent);
Toast.makeText(getApplicationContext(), "Opening detailed view for:"+eventTitleArray[position], Toast.LENGTH_SHORT).show();
}
});
i have this customized list. each row contains an image and two lines of text one below the other. i want to open a new activity when any list item is clicked. but i am not able to do so, even after implementing the setOnItemClickListener(). please correct me if i am wrong. the below is the code for the list.
PS: This is an normal activity and not list activity.
l1.setAdapter(new EfficientAdapter(this,eventTitleArray,eventDateArray,eventImageLinkArray));
//l1 = getListView();
l1.setClickable(true);
l1.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int position, long arg3) {
Intent intent = new Intent(MainActivity.this, DisplayActivity.class);
Bundle b = new Bundle();
b.putString("event", eventTitleArray[position]);
intent.putExtras(bundle);
startActivity(intent);
Toast.makeText(getApplicationContext(), "Opening detailed view for:"+eventTitleArray[position], Toast.LENGTH_SHORT).show();
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请查看行布局是否有可聚焦的项目。如果 ListView 项包含可聚焦的子项,则不会触发 Listview 处理程序。
Please have a look whether the row layout has any items which are focusable. If an ListView Item contains focusable children, the Listview Handler will not be fired.
我认为 SDK 中存在一个错误,当项目视图中有可聚焦视图时,该错误会阻止 onItemClickListeners 触发。
因此,您应该尝试对项目的所有视图执行 setFocusable(false) 。
该问题已描述此处
I think there is a bug in the SDK that prevents the onItemClickListeners from firing when there are focusable views in the View of your items.
So you should try to do a setFocusable(false) on all the Views of your items.
The problem is described here