ListView中多个EditText焦点处理问题

lucers 2016-11-11 06:09:24
如题,目前我ListView的Item中有多个EditText,下面是我Item的布局文件,现在的问题是我点击EditText的他会弹出键盘,但是EditText并没有获取到焦点,无法输入.只有我再出点击的时候才能进行输出

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusableInTouchMode="true"
android:orientation="vertical" >

<TextView
android:id="@+id/tv_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:background="#D9DADC"
android:gravity="center"
android:padding="5dp"
android:text="家庭成员1" />

<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:orientation="vertical" >

<TableRow android:layout_marginTop="5dp" >

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="称 谓" />

<EditText
android:id="@+id/et_appellation"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="@drawable/text"
android:textColor="#88740606" />
</TableRow>

<TableRow android:layout_marginTop="5dp" >

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="姓 名" />

<EditText
android:id="@+id/et_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="@drawable/text"
android:textColor="#88740606" />
</TableRow>

<TableRow android:layout_marginTop="5dp" >

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="工作单位" />

<EditText
android:id="@+id/et_workplace"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="@drawable/text"
android:textColor="#88740606" />
</TableRow>

<TableRow android:layout_marginTop="5dp" >

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="职 务" />

<EditText
android:id="@+id/et_position"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="@drawable/text"
android:textColor="#88740606" />
</TableRow>

<TableRow android:layout_marginTop="5dp" >

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="联系方式" />

<EditText
android:id="@+id/et_phone"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="@drawable/text"
android:textColor="#88740606" />
</TableRow>

<TableRow android:layout_marginTop="5dp" >

<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:text="其 他" />

<EditText
android:id="@+id/et_else"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_weight="1"
android:background="@drawable/text"
android:textColor="#88740606" />
</TableRow>
</TableLayout>

</LinearLayout>
...全文
315 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
程序猿小爱 2016-12-01
  • 打赏
  • 举报
回复
我前段时间就弄了一个item多个edittext编辑框焦点问题,建议有请求焦点和setOnFocusChangeListener方法结合使用。
lucers 2016-11-22
  • 打赏
  • 举报
回复
引用 2 楼 IT_ZJYANG 的回复:
这是因为ListView的重绘机制导致EditText失去焦点 原因:在你点击弹出软键盘的那一刻,软键盘会将ListView挤压,导致,ListView重绘,从而导致EdittEext也重绘,同时焦点也失去,所以需要重新强制获取焦点。 详情参考:http://blog.csdn.net/it_zjyang/article/details/52808936
原因是这样的,不过如果只有一个EditText看了资料我就解决了,可是我这里面EditText太多了..
IT_ZJYANG 2016-11-13
  • 打赏
  • 举报
回复
这是因为ListView的重绘机制导致EditText失去焦点 原因:在你点击弹出软键盘的那一刻,软键盘会将ListView挤压,导致,ListView重绘,从而导致EdittEext也重绘,同时焦点也失去,所以需要重新强制获取焦点。 详情参考:http://blog.csdn.net/it_zjyang/article/details/52808936
LoveWyf_ 2016-11-11
  • 打赏
  • 举报
回复
你手动调用一下editText.setFocusable(true); editText.setFocusableInTouchMode(true); editText.requestFocus(); 来强制获得焦点

80,361

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧