android 列表视图可点击问题

发布于 2024-10-05 01:44:15 字数 844 浏览 3 评论 0原文

我有这个定制清单。每行包含一个图像和两行文本,一行位于另一行下方。我想在单击任何列表项时打开一个新活动。但即使在实现 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

泪冰清 2024-10-12 01:44:15

请查看行布局是否有可聚焦的项目。如果 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.

恍梦境° 2024-10-12 01:44:15

我认为 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文