块后代(Android)时专注于ListView中的EditText

块后代(Android)时专注于ListView中的EditText,第1张

概述我有一个自定义的ListView.每行都有一个EditText,Buttons& TextView中.为了使ListView项目可单击,我保留了 android:descendantFocusability =“blocksDescendants”用于行布局.如果我不保留descendantFocusability,我无法为onItemClick实现一个动作.如果我保持descendantFocu 我有一个自定义的ListVIEw.每行都有一个EditText,buttons& TextVIEw中.为了使ListVIEw项目可单击,我保留了 android:descendantFocusability =“blocksDescendants”用于行布局.如果我不保留descendantFocusability,我无法为onItemClick实现一个动作.如果我保持descendantFocusability,我的行中存在的EditText没有获得焦点.我希望EditText是可聚焦的,我也应该能够点击每一行来导航到另一个Activity.任何人都可以帮助我.谢谢大家.

编辑:在EditAdxt的CustomAdapter中,我尝试保持ontouchListenerand也onClickListener我requestFocus,但这似乎不起作用.

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"

谢谢,并享受此代码!

总结

以上是内存溢出为你收集整理的块后代(Android)时专注于ListView中的EditText全部内容,希望文章能够帮你解决块后代(Android)时专注于ListView中的EditText所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1136834.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存