1. 程式人生 > >ListView中EditText無法獲取焦點

ListView中EditText無法獲取焦點

group 解決方法 red sel focus end oid abi 分享

原文地址:http://www.cnblogs.com/skyseraph/archive/2013/04/21/3033848.html

  要解決這個問題,我們先要了解android:descendantFocusability這個屬性.這個屬性有三個值:

beforeDescendants: viewgroup會優先其子類控件而獲取到焦點

afterDescendants: viewgroup只有當其子類控件不需要獲取焦點時才獲取焦點

blocksDescendants: viewgroup會覆蓋子類控件而直接獲得焦點

  

  解決思路就是ListView中的item被選中的時候,讓其中的EditText優先取得焦點,當EditText失去焦點時,焦點返回到ListView中

1 通過設置focus停在ListView上,解決ListView無法點擊的問題。方法如下:

  技術分享圖片

2 在ListView中setOnItemSelectedListener的onItemSelected 和 onNothingSelected分別輸入下述代碼

  技術分享圖片

3 無法調出輸入法問題,網上博文(點擊打開鏈接),解決方法如下(此問題我沒碰到):

  技術分享圖片

ListView中EditText無法獲取焦點