当块后代时关注 ListView 中的 EditText (Android)

2024-01-09

我有一个定制的ListView。每行都有一个EditText, Buttons & TextView。为了使 ListView 项目可点击,我保留了android:descendantFocusability="blocksDescendants"用于行布局。如果我不保留后代聚焦性我无法执行以下操作onItemClick。如果我保留后代聚焦性 the EditText我的行中存在的内容没有引起关注。我想要EditText可聚焦,而且我应该能够单击每一行以导航到另一行Activity。任何人都可以帮助我吗?谢谢大家。

编辑:在 EditText 的 CustomAdapter 中,我尝试保留onTouchListener并且onClickListener我请求焦点,但这似乎不起作用。

row.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recentrowLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/margin_left_5"
android:clickable="true"
tools:ignore="UseCompoundDrawables,HardcodedText,ContentDescription,UselessParent" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/edit_text_bg"
    android:padding="@dimen/margin_left_5" >

    <RelativeLayout
        android:id="@+id/rl1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >

        <ImageView
            android:id="@+id/addSubscribe"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true" />

        <TextView
            android:id="@+id/flikart_textview"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:text="FLIKART"
            android:textColor="@color/gray"
            android:textSize="@dimen/medium_text_size" />

        <ImageView
            android:id="@+id/addToFav"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true" />
    </RelativeLayout>

    <LinearLayout
        android:id="@+id/rl2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/rl1"
        android:layout_marginLeft="@dimen/margin_30"
        android:layout_marginRight="@dimen/margin_30"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/text_desciption"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:gravity="center_horizontal"
            android:lines="2"
            android:text="20% off on Smart Phones and basic Handsets has upto 50% OFF only"
            android:textColor="@color/blue" />

        <TextView
            android:id="@+id/text_desciption2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:lines="1"
            android:text="somethign something,......."
            android:textColor="@color/gray" />

        <TextView
            android:id="@+id/couponTypeText"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/margin_left_10"
            android:background="@drawable/button_bg"
            android:gravity="center"
            android:padding="@dimen/margin_left_10"
            android:text="STEAL THE DEAL"
            android:textColor="@color/white"
            android:textSize="@dimen/little_small_text_size" />
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/rl3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/rl2"
        android:layout_marginTop="@dimen/margin_left_10" >

        <TextView
            android:id="@+id/text_offer_expiry"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="@dimen/margin_left_5"
            android:text="Ends 10 days"
            android:textColor="@color/red"
            android:textSize="16sp" />

        <RelativeLayout
            android:id="@+id/rightLayout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="5dp" >

            <ImageView
                android:id="@+id/comment_image_total"
                android:layout_width="@dimen/dimenstion_25"
                android:layout_height="@dimen/dimenstion_20"
                android:background="@drawable/comments" />

            <TextView
                android:id="@+id/text_comments"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@id/comment_image_total"
                android:text="100 Comments"
                android:textColor="@color/gray"
                android:textSize="16sp" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/ll2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_toLeftOf="@id/rightLayout"
            android:layout_toRightOf="@id/text_offer_expiry"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/like_image_total"
                android:layout_width="@dimen/dimenstion_25"
                android:layout_height="@dimen/dimenstion_25"
                android:background="@drawable/like" />

            <TextView
                android:id="@+id/text_total_likes"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@id/like_image_total"
                android:text="999 Likes"
                android:textColor="@color/gray"
                android:textSize="16sp" />
        </RelativeLayout>
    </RelativeLayout>

    <View
        android:id="@+id/view"
        android:layout_width="fill_parent"
        android:layout_height="4dp"
        android:layout_below="@id/rl3"
        android:layout_marginTop="@dimen/margin_5"
        android:background="@color/purple_clor" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="@dimen/title_bar_height"
        android:layout_below="@id/view"
        android:layout_centerVertical="true"
        android:layout_marginTop="@dimen/margin_5" >

        <RelativeLayout
            android:id="@+id/likesLayout"
            android:layout_width="@dimen/dimenstion_40"
            android:layout_height="@dimen/dimenstion_40"
            android:layout_centerVertical="true"
            android:background="@drawable/unratedbkg" >

            <Button
                android:id="@+id/likesBtn"
                android:layout_width="@dimen/dimenstion_30"
                android:layout_height="@dimen/dimenstion_30"
                android:layout_centerInParent="true"
                android:background="@drawable/unrated" />
        </RelativeLayout>

        <RelativeLayout
            android:id="@+id/footermain"
            android:layout_width="fill_parent"
            android:layout_height="@dimen/dimenstion_40"
            android:layout_centerVertical="true"
            android:layout_toRightOf="@id/likesLayout"
            android:background="@color/white" >

            <RelativeLayout
                android:id="@+id/animLayout"
                android:layout_width="100dp"
                android:layout_height="@dimen/dimenstion_40"
                android:layout_marginLeft="10dp"
                android:layout_toRightOf="@id/likesLayout"
                android:background="@drawable/ratingbkg"
                android:visibility="gone" >

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentLeft="true"
                    android:layout_margin="@dimen/margin_5" >

                    <ImageView
                        android:id="@+id/like_image"
                        android:layout_width="@dimen/dimenstion_30"
                        android:layout_height="@dimen/dimenstion_30"
                        android:layout_centerInParent="true"
                        android:background="@drawable/like" />
                </RelativeLayout>

                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentRight="true"
                    android:layout_margin="@dimen/margin_5" >

                    <ImageView
                        android:id="@+id/dislike_image"
                        android:layout_width="@dimen/dimenstion_30"
                        android:layout_height="@dimen/dimenstion_30"
                        android:layout_centerInParent="true"
                        android:background="@drawable/dislike" />
                </RelativeLayout>
            </RelativeLayout>

            <EditText
                android:id="@+id/add_comment"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_marginLeft="5dp"
                android:layout_toRightOf="@id/animLayout"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:hint="Add Comment"
                android:inputType="text" />
        </RelativeLayout>
    </RelativeLayout>
</RelativeLayout>

</LinearLayout>

请不要使用 setOnItemClickListener 进行项目单击..我认为您应该使用项目视图单击适配器方法内部

convertView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(context, "click item",Toast.LENGTH_LONG).show();
            }
        });

从主列表项布局中删除它

android:descendantFocusability="blocksDescendants" 

谢谢并享受这个代码!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

当块后代时关注 ListView 中的 EditText (Android) 的相关文章

随机推荐

  • jQuery:仅在父链接上防止默认

    解决方案 找到了解决方案 使用的父节点 skaftetopmenu li gt a click function e e preventDefault var subid this parentNode attr id if subid f
  • ActiveRecord::Relation#bind 的目的是什么?

    只是出于好奇 我正在阅读的文档关系 查询方法模块 http apidock com rails v3 2 8 ActiveRecord QueryMethods bind并找到了该方法 def bind value relation clo
  • 具有 4 个视图控制器的页面视图控制器 - 如何将视图 2 设置为初始视图控制器?

    我创建了一个带有四个视图控制器的 pageViewController 现在的顺序是 VC1 VC2 VC3 VC4 var pageControl UIPageControl var pendingPage Int lazy var vi
  • 如何取消handler.postDelayed?

    如果我有怎么办handler postDelayed线程已经在执行中 我需要取消它吗 我这样做是为了取消 postDelays 根据 Android 删除回调 http developer android com reference and
  • d3.event.pageX & d3.mouse(this)[0]

    我试图找出 d3 event pageX 和 d3 mouse this 0 之间的区别 我猜两者是相同的 但是 当我 console log 两者时 我的代码中的值与 8 不同 var height 600 var width 600 v
  • 如果用户未使用电子邮件注册,Firebase 身份验证标识符会从 Facebook 登录存储什么值

    如果用户不是使用电子邮件注册而是使用电话号码注册 Firebase 身份验证标识符会从 Facebook 登录存储什么值 我的应用程序提供 facebook 登录 但现在当用户使用 Facebook 登录时 我的 firebase 身份验证
  • ionic框架同步数据并离线工作

    我正在使用 ionic 框架开发一个应用程序 它将从使用 laravel 构建的 API 中获取一些数据 将其保存在数据库中 以便当用户离线时他可以继续使用该应用程序 我对在互联网上找到了一个名为 pouchDB 的插件 是否推荐它满足我的
  • 如何在 Vim 中删除(所需文本)、删除(不需要的文本)和粘贴(所需文本)

    我不知道这是否是一个弱智问题 但这是一个有趣的困境 当我想删除我想放在其他地方的文本 但那个地方有其他一堆我不想要的文本时 我会删除该文本 但在此过程中我复制一个新的剪贴板 以便以前删除的文本消失 有什么建议来解决这个问题吗 一些可能的解决
  • Unity Visual Studio C#版本同步

    我刚刚开始在 Unity 游戏中使用委托和事件在适当的时候更新标签 而不是每帧更新标签 尽管大多数时候没有发生任何变化 为了确保静态事件调用 public static event OnSomething onSomething 实际上有听
  • 容器“gcr.io/google_containers/pause:0.8.0”中的进程做了什么工作?

    我已经清楚地了解了 docker 选项的用法 net container NAME or ID 我还阅读了kubernetes的源代码 了解如何配置容器使用网络InfraContainer 所以我认为唯一在容器中工作的过程gcr io go
  • 如何根据阈值改变字体颜色

    我有一个要求 比如如果阈值大于 6 则文本颜色应显示为红色 在 5 6 之间 文本颜色应更改为黄色 我在第一个要求 iif fields My column value gt 6 red Black 的文本框字体颜色属性中尝试了这个表达式
  • 最有效的方法...唯一的随机字符串

    我需要有效地将 5 个字符的随机字符串插入数据库 同时确保它是唯一的 生成随机字符串不是问题 但目前我正在做的是生成字符串 然后检查数据库是否已经存在 如果存在 我会重新开始 有没有更有效的方法来完成这个过程 请注意 我不想使用 GUID
  • 如何在 keydown 中停止按键事件

    我怎样才能停下来keypresskeydown 处理程序中的事件 即使从 keydown 中也无法停止按键 它们都是非常独立的事件 您可以做的是在读取字符后取消按键 按键 这是我只允许在文本框中输入字母和数字的方法 jQuery urlBo
  • Nuxt Vue 中的 Splidejs

    有没有人尝试过在 Nuxt 中使用 Vue 解决方案作为插件或模块 我在尝试以正确的方式做到这一点时遇到了很多挑战 我正在尝试将 Splide Vue 滑块从 NPM 导入 Nuxt 通过 NPM 安装它后 如何将其导入插件中的 splid
  • “->”(箭头运算符)和“.”有什么区别Objective-C 中的(点运算符)?

    在 Objective C 中 通过使用访问类中的变量有什么区别 gt 箭头运算符 和 点运算符 是 gt 用于直接访问 vs 点 不是直接的吗 gt 是传统的 C 运算符 用于访问指针引用的结构的成员 由于 Objective C 对象
  • 在 Safari 中隐藏文本区域调整大小手柄

    我在应用程序中使用文本区域组件 并动态控制它们的高度 当用户键入时 只要有足够的文本 高度就会增加 这在 IE Firefox 和 Safari 上运行良好 然而 在 Safari 中 右下角有一个 手柄 工具 允许用户通过单击和拖动来调整
  • 如何将 dapper 与 ASP.Net core Identity 结合使用?

    我有一个数据库 我尝试使用 dapper 和 Core Identity 来查询数据库 但我现在陷入困境 我正在使用 IdentityUser 界面中的用户 public class User IdentityUser 使用 dapper
  • 使用 SemanticResultKey 时出现 TargetInitationException

    我想建立我的语法来接受多个数字 当我重复数字 例如说 二十一 时 它有一个错误 所以我不断减少代码来找出问题所在 我为语法生成器编写了以下代码 string numberString one Choices numberChoices ne
  • Orchard 根据过滤的下拉选择创建投影或搜索

    我认为 我有一个简单的功能 我试图将其添加到我的 Orchard 1 6 站点 但我找不到任何有关如何执行此操作的教程或说明 我有一个名为 Office 的自定义类型 每个办公室都有一个名为 State 的自定义字段 指示办公室所在的州 实
  • 当块后代时关注 ListView 中的 EditText (Android)

    我有一个定制的ListView 每行都有一个EditText Buttons TextView 为了使 ListView 项目可点击 我保留了android descendantFocusability blocksDescendants