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: