Android:ListView 中的 QuickContactBadge

发布于 2024-11-08 06:47:31 字数 1317 浏览 5 评论 0原文

首先是场景:

我有一个列表,其中每个项目都有联系人的照片和一些文本。我想单击图像并调出 QuickContactBadge。徽章由以下 XML 片段定义

<QuickContactBadge android:layout_height="wrap_content"
   android:layout_width="wrap_content" android:id="@+id/badge" 
   android:layout_alignParentBottom="true"></QuickContactBadge>

我尝试过但失败了:

  1. 定义一个可重用徽章并在所有情况下重用它。列表和徽章都放置在 RelativeLayout 中,
  2. 为每个列表项定义一个徽章。该项目使用 RelativeLayout

我看到了什么:

基本上什么也没有。代码获取有效的徽章实例,然后应用以下逻辑

    contactPhoto.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            Log.d(TAG, "Image click");
            if (badge != null) {
                badge.assignContactFromEmail("[email protected]", true);
                badge.setMode(ContactsContract.QuickContact.MODE_SMALL);
                badge.bringToFront();
            }
        }
    });

当我单击时,我可以单步执行 onClick 处理程序中的代码,但徽章从未出现

问题:

  1. QuickContactBadge 是否会 出现?有什么放置逻辑吗?当我单击图像时,我是否需要计算徽章位置并重新调整,还是它是内置的?
  2. 是否有可能实现我上面描述的内容(列表中显示的图像徽章)以及我做错了什么(或丢失)

First the scenario:

I have a list where each item has a photo of a contact and some text. I would like to click on the image and bring up the QuickContactBadge. Badge is defined by the following XML snippet

<QuickContactBadge android:layout_height="wrap_content"
   android:layout_width="wrap_content" android:id="@+id/badge" 
   android:layout_alignParentBottom="true"></QuickContactBadge>

What I tried and failed:

  1. Define one reusable badge and reuse it for all cases. Both list and badge are placed into RelativeLayout
  2. Have one badge defined per each list item. The item uses RelativeLayout

What do I see:

Basically nothing. The code gets valid badge instance and then I apply the following logic

    contactPhoto.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(final View v) {
            Log.d(TAG, "Image click");
            if (badge != null) {
                badge.assignContactFromEmail("[email protected]", true);
                badge.setMode(ContactsContract.QuickContact.MODE_SMALL);
                badge.bringToFront();
            }
        }
    });

As I click I can step through the code in onClick handler yet the badge never comes up

The questions:

  1. Does QuickContactBadge have any placement logic? When I click on the image do I need to calculate badge position and readjust or is it built-in?
  2. Is it possible to achieve what I describe above (badge for images displayed in the list) and what I'm doing wrong (or missing)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

还给你自由 2024-11-15 06:47:31

中止!中止!

基本上我完全误解了徽章是什么以及如何使用它。我想做的是检测图像上的点击并调用徽章。这从根本上是错误的,因为我所需要做的只是在代码中使用 QuickContactBadge 而不是 ImageView 。当我用项目中的徽章替换图像后,XML 魔法就自动出现了。

据说 - 可以使用代码弹出徽章,请参阅 this关于如何做到这一点的文章

Abort! Abort!

Basically I totally misunderstood what the badge is and how to use it. What I was trying to do is to detect click on image and call the badge. This is fundamentally wrong since all I needed to do was to simply use QuickContactBadge INSTEAD of ImageView in my code. After I replaced images with badges in the item XML magic was automatically there.

Said that - it is possible to pop the badge using the code, refer to this article on how to do it

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