Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了块后代(Android)时专注于ListView中的EditText大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个自定义的ListView.每行都有一个EditText,Buttons& TextView中.为了使ListView项目可单击,我保留了 android:descendantFocusability =“blocksDescendants”用于行布局.如果我不保留descendantFocusability,我无法为onItemClick实现一个动作.如果我保持descendantFocusability,我的行中存在的EditText没有获得焦点.我希望EditText是可聚焦的,我也应该能够点击每一行来导航到另一个Activity.任何人都可以帮助我.谢谢大家.

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

row.xml@H_197_3@

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://scheR_109_11845@as.android.com/apk/res/android"
xmlns:tools="http://scheR_109_11845@as.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_@R_861_10586@l"
                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_@R_861_10586@l"
                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_@R_861_10586@l"
                android:layout_width="@dimen/dimenstion_25"
                android:layout_height="@dimen/dimenstion_25"
                android:BACkground="@drawable/like" />

            <TextView
                android:id="@+id/text_@R_861_10586@l_likes"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_toRightOf="@id/like_image_@R_861_10586@l"
                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();
            }
        });

从主列表项布局中删除它@H_197_3@

android:descendantFocusability="blocksDescendants"

谢谢,并享受此代码!@H_197_3@

大佬总结

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

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。