![](/img/trans.png)
[英]EditText loses focus after resizing ListView when keyboard is displayed
[英]Numeric edittext loses focus after first input in listview
我的列表視圖中有多個編輯文本,數字和普通。 當我點擊一個數字時,它會獲得焦點並彈出鍵盤,但在我輸入 1 個數字后,它失去了焦點,我必須再次點擊它才能輸入更多數字。 有沒有辦法保持專注,以便我可以輸入更多數字? 我的正常編輯文本工作得很好。
我已經嘗試過使用 adjustpan 和不同的鍵盤模式。
編輯文本代碼:
<EditText
android:id="@+id/etEditTextItem"
android:inputType="number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="5"
android:focusable="true"
android:focusableInTouchMode="true"
android:layout_alignParentRight="true" />
列表視圖代碼:
<ExpandableListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/colorCard"
android:groupIndicator="@null">
</ExpandableListView>
問題是列表視圖:您必須在列表視圖活動中添加以下內容才能顯示
android:windowSoftInputMode="adjustPan"
和以下列表視圖
android:descendantFocusability="beforeDescendants"
我設法修復了它,在調試 currentFocus 后我發現 listview onExpand() 將焦點移開了,在將焦點返回到 edittext 后設置了 editText.requestfocus()。
我有同樣的問題,但我的 EditText 不在任何 ListView 中。 它只是在幾個嵌套的 LinearLayouts 內,並且也失去了它的焦點。 解決我的問題是在活動代碼和 onTextChanged 中為此 EditText 添加 TextChangedListener 我設置:
EditText.requestFocusFromTouch()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.