常常會碰到在ListView中點擊當中一個Item。會一並觸發其子控件的點擊事件。比如Item中的Button、ImageButton等。導致了點擊Item中Button以外區域也會觸發Button點擊事件。在網上找了相關方法,這里記錄下。親測可行..
1、在Item的xml文件根元素中加入屬性:android:descendantFocusability="blocksDescendants"
2、在沖突的子控件中加入屬性:android:focusable="false"和android:clickable="true"
網上有人說步驟2不須要也行。但在項目中試了不行,所以說步驟2還是須要的..