重点的EditText ListView中时,块后裔(安卓) [英] Focus on EditText in ListView when block descendants (Android)
问题描述
我有一个自定义的的ListView 。每行有一个的EditText,按钮和放大器;的TextView
。为了使ListView的项目可点击我一直安卓为行布局descendantFocusability =blocksDescendants
。如果我不保持在 descendantFocusability 我不能够实施 onItemClick
的行动。如果我继续的 descendantFocusability 的的EditText
这是present在我行未获得焦点。我想的EditText
可聚焦的,也是我应该可以点击每一行上导航到另一个活动
。任何人都可以请帮我在这。感谢所有。
编辑:在CustomAdapter的EditText上,我试图保持 onTouchListener
也 onClickListener
在这里我不是requestFocus但也不似乎不工作。
row.xml
< XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
的xmlns:工具=http://schemas.android.com/tools
机器人:ID =@ + ID / recentrowLayout
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:填充=@扪/ margin_left_5
机器人:可点击=真
工具:忽略=UseCompoundDrawables,硬codedText,ContentDescription,UselessParent>
< RelativeLayout的
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:背景=@可绘制/ edit_text_bg
机器人:填充=@扪/ margin_left_5>
< RelativeLayout的
机器人:ID =@ + ID / RL1
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT>
< ImageView的
机器人:ID =@ + ID / addSubscribe
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真/>
<的TextView
机器人:ID =@ + ID / flikart_textview
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerInParent =真
机器人:文本=FLIKART
机器人:文字颜色=@彩色/灰度
机器人:TEXTSIZE =@扪/ medium_text_size/>
< ImageView的
机器人:ID =@ + ID / addToFav
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentRight =真/>
< / RelativeLayout的>
<的LinearLayout
机器人:ID =@ + ID / RL2
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ ID / RL1
机器人:layout_marginLeft =@扪/ margin_30
机器人:layout_marginRight =@扪/ margin_30
机器人:layout_marginTop =10dp
机器人:重力=中心
机器人:方向=垂直>
<的TextView
机器人:ID =@ + ID / text_desciption
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_gravity =center_horizontal
机器人:重力=center_horizontal
机器人:行=2
机器人:文本=20%的智能手机和基本手机有高达50%的折扣只有
机器人:文字颜色=@色/蓝色/>
<的TextView
机器人:ID =@ + ID / text_desciption2
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =10dp
机器人:行=1
机器人:文本=somethign东西,......
机器人:文字颜色=@彩色/灰度/>
<的TextView
机器人:ID =@ + ID / couponTypeText
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_marginTop =@扪/ margin_left_10
机器人:背景=@可绘制/ button_bg
机器人:重力=中心
机器人:填充=@扪/ margin_left_10
机器人:文本=偷DEAL
机器人:文字颜色=@色/白
机器人:TEXTSIZE =@扪/ little_small_text_size/>
< / LinearLayout中>
< RelativeLayout的
机器人:ID =@ + ID / RL3
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ ID / RL2
机器人:layout_marginTop =@扪/ margin_left_10>
<的TextView
机器人:ID =@ + ID / text_offer_expiry
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真
机器人:layout_centerVertical =真
机器人:layout_marginRight =@扪/ margin_left_5
机器人:文本=端10日
机器人:文字颜色=@色/红
机器人:TEXTSIZE =16SP/>
< RelativeLayout的
机器人:ID =@ + ID / rightLayout
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentRight =真
机器人:layout_centerVertical =真
机器人:layout_marginRight =5DP>
< ImageView的
机器人:ID =@ + ID / comment_image_total
机器人:layout_width =@扪/ dimenstion_25
机器人:layout_height =@扪/ dimenstion_20
机器人:背景=@可绘制/评论/>
<的TextView
机器人:ID =@ + ID / text_comments
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerVertical =真
机器人:layout_toRightOf =@ ID / comment_image_total
机器人:文本=100评论
机器人:文字颜色=@彩色/灰度
机器人:TEXTSIZE =16SP/>
< / RelativeLayout的>
< RelativeLayout的
机器人:ID =@ + ID / [112
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerVertical =真
机器人:layout_marginLeft =10dp
机器人:layout_marginRight =10dp
机器人:layout_toLeftOf =@ ID / rightLayout
机器人:layout_toRightOf =@ ID / text_offer_expiry
机器人:重力=center_horizontal>
< ImageView的
机器人:ID =@ + ID / like_image_total
机器人:layout_width =@扪/ dimenstion_25
机器人:layout_height =@扪/ dimenstion_25
机器人:背景=@可绘制/像/>
<的TextView
机器人:ID =@ + ID / text_total_likes
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerVertical =真
机器人:layout_toRightOf =@ ID / like_image_total
机器人:文本=999喜欢
机器人:文字颜色=@彩色/灰度
机器人:TEXTSIZE =16SP/>
< / RelativeLayout的>
< / RelativeLayout的>
<查看
机器人:ID =@ + ID /视图
机器人:layout_width =FILL_PARENT
机器人:layout_height =4DP
机器人:layout_below =@ ID / RL3
机器人:layout_marginTop =@扪/ margin_5
机器人:背景=@色/ purple_clor/>
< RelativeLayout的
机器人:layout_width =FILL_PARENT
机器人:layout_height =@扪/ title_bar_height
机器人:layout_below =@ ID /视图
机器人:layout_centerVertical =真
机器人:layout_marginTop =@扪/ margin_5>
< RelativeLayout的
机器人:ID =@ + ID / likesLayout
机器人:layout_width =@扪/ dimenstion_40
机器人:layout_height =@扪/ dimenstion_40
机器人:layout_centerVertical =真
机器人:背景=@可绘制/ unratedbkg>
<按钮
机器人:ID =@ + ID / likesBtn
机器人:layout_width =@扪/ dimenstion_30
机器人:layout_height =@扪/ dimenstion_30
机器人:layout_centerInParent =真
机器人:背景=@可绘制/未分级/>
< / RelativeLayout的>
< RelativeLayout的
机器人:ID =@ + ID / footermain
机器人:layout_width =FILL_PARENT
机器人:layout_height =@扪/ dimenstion_40
机器人:layout_centerVertical =真
机器人:layout_toRightOf =@ ID / likesLayout
机器人:背景=@色/白>
< RelativeLayout的
机器人:ID =@ + ID / animLayout
机器人:layout_width =100dp
机器人:layout_height =@扪/ dimenstion_40
机器人:layout_marginLeft =10dp
机器人:layout_toRightOf =@ ID / likesLayout
机器人:背景=@可绘制/ ratingbkg
机器人:能见度=水涨船高>
< RelativeLayout的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentLeft =真
机器人:layout_margin =@扪/ margin_5>
< ImageView的
机器人:ID =@ + ID / like_image
机器人:layout_width =@扪/ dimenstion_30
机器人:layout_height =@扪/ dimenstion_30
机器人:layout_centerInParent =真
机器人:背景=@可绘制/像/>
< / RelativeLayout的>
< RelativeLayout的
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentRight =真
机器人:layout_margin =@扪/ margin_5>
< ImageView的
机器人:ID =@ + ID / dislike_image
机器人:layout_width =@扪/ dimenstion_30
机器人:layout_height =@扪/ dimenstion_30
机器人:layout_centerInParent =真
机器人:背景=@可绘制/不喜欢/>
< / RelativeLayout的>
< / RelativeLayout的>
<的EditText
机器人:ID =@ + ID / add_comment
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_centerVertical =真
机器人:layout_marginLeft =5DP
机器人:layout_toRightOf =@ ID / animLayout
机器人:可聚焦=假
机器人:focusableInTouchMode =假
机器人:提示=添加注释
机器人:inputType =文本/>
< / RelativeLayout的>
< / RelativeLayout的>
< / RelativeLayout的>
< / LinearLayout中>
请不要使用setOnItemClickListener的产品Click ..我认为你应该使用项目视图点击里面的适配器方法
convertView.setOnClickListener(新OnClickListener(){
@覆盖
公共无效的onClick(视图v){
Toast.makeText(背景下,点击项目,Toast.LENGTH_LONG).show();
}
});
从主列表项的布局中删除此
安卓descendantFocusability =blocksDescendants
感谢和享受这个code!
I have a customized ListView. Each row has an EditText, Buttons & TextView
. In order to make the ListView items clickable I have kept android:descendantFocusability="blocksDescendants"
for row layout. If I don't keep the descendantFocusability I am not able to implement an action for onItemClick
. If I keep descendantFocusability the EditText
which is present in my row is not gaining focus. I want the EditText
focusable and also I should be able to click on each row to navigate to another Activity
. Can anyone please help me in this. Thanks all.
Edit : In the CustomAdapter for EditText, I tried keeping onTouchListener
and also onClickListener
where I requestFocus but that does not seem to work.
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>
please Don't use setOnItemClickListener for item click .. i think that you should be use item view click inside adapter method
convertView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, "click item",Toast.LENGTH_LONG).show();
}
});
Remove this from main list item layout
android:descendantFocusability="blocksDescendants"
Thanks and enjoy this code !
这篇关于重点的EditText ListView中时,块后裔(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!