android:ListView中使用EditText,遇到的坑,获取点击焦点、保存输入文本的demo

这篇博客介绍了在Android中使用ListView与EditText时遇到的焦点丢失和显示错乱问题,提供了完整的代码示例和效果图,帮助开发者避免此类问题。
摘要由CSDN通过智能技术生成

ListView一般是展示图标、文字,用户点击Item后,触发某些事件响应,很少会使用EditText,刚使用了下,发现还是有一点小坑的,记录下来,防止以后再踩坑里。

具体的解释后面看看是不是需要补上,暂时把带有注释的完整代码放上,保证能够直接跑起来就好。

效果图如下:






首先activity里面的布局如下activity_main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ListView
        android:id="@+id/list_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

上面只是展示一个ListView,match_parent,这里没的说,比较简单。


然后是ListView中,每一个Item的布局my_item.xml:

<?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" >

    <ImageView
        android:id="@+id/my_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" 
        android:contentDescription="image_desc"/>

    <TextView
        android:id="@+id/my_desc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginLeft="10dip" />

    <EditText
        android:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值