http://blog.csdn.net/lxzh12345/article/details/9526483
最近有人问我,在Android里:
在自定义listView里面有按钮,然后setItemClickListener时不响应,网上很多关于这个的,但我都试过,貌似都解决不了。
其实刚开始学Android接触ListView时我也遇到此问题,在网上到处搜也难以找到相关解决方案,原因之一是网上原创文章少,转载居多,很多文章都雷同;原因之二在于自己英语不好,不敢上外文论坛去找。
后来经过自己的慢慢摸索终于解决了这个问题。
当朋友问我时,我一番简单讲解加几张代码截图就给他解决问题啦~
废话不多说,先上源代码:源代码
代码片段:
main.xml
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@drawable/background" >
- <ListView
- android:id="@+id/lv_list"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:layout_alignParentLeft="true"
- android:layout_below="@+id/numxback"
- android:cacheColorHint="#00000000"
- android:drawSelectorOnTop="false"
- android:fadingEdge="none"
- android:fastScrollEnabled="true"
- android:focusable="false"
- android:divider="@null"
- android:focusableInTouchMode="true"
- android:listSelector="@drawable/itemselected" />
- </RelativeLayout>
在main布局里加入了一个列表控件,ListView,它的各个属性在此处不是重点,这里就不多说,看不懂的读者自己去网上搜吧!
datalist.xml
- <?xml version="1.0" encoding="utf-8"?>
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/widget_datalist"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:descendantFocusability="blocksDescendants">
- <TextView
- android:id="@+id/tv_num"
- android:layout_width="wrap_content"
- android:layout_height="60px"
- android:layout_centerVertical="true"
- android:background="@drawable/number"
- android:gravity="center"
- android:paddingLeft="5px"
- android:paddingRight="8px"
- android:textColor="@android:color/white"
- android:textSize="24sp" />
- <ImageButton
- android:id="@+id/ib_edit"
- android:layout_width="60px"
- android:layout_height="60px"
- android:layout_alignParentRight="true"
- android:background="@drawable/edit"
- <span style="color:#ff0000">android:onClick="OnItemEditClick"
- </span> android:paddingRight="5px" />
- <TextView
- android:id="@+id/tv_numx"
- android:layout_width="150px"
- android:layout_height="60px"
- android:layout_toRightOf="@+id/tv_num"
- android:background="@drawable/number"
- android:gravity="center_vertical"
- android:singleLine="true"
- android:textColor="@android:color/white"
- android:textSize="24sp" />
- <TextView
- android:id="@+id/tv_numy"
- android:layout_width="150px"
- android:layout_height="60px"
- android:layout_toRightOf="@id/tv_numx"
- android:layout_toLeftOf="@id/ib_edit"
- android:background="@drawable/number"
- android:gravity="center_vertical"
- android:singleLine="true"
- android:textColor="@android:color/white"
【上篇】反转一个字节 和 判断32位整数二进制中1的个数 的算法
【下篇】There is no Action mapped for namespace / and action name . – [unknown location]
【下篇】There is no Action mapped for namespace / and action name . – [unknown location]