問題描述
我在列表視圖中有一些編輯文本.我在edittext上有一個通用的focuslistener,它通過調(diào)用notifydatachanged更新數(shù)據(jù)模型的值以及當(dāng)焦點丟失時edittext的背景.問題是,如果其中一個編輯文本保持焦點,當(dāng)我觸摸下一個編輯文本時,它會暫時獲得焦點然后失去焦點.我懷疑這是由于 notifydatachanged 方法調(diào)用導(dǎo)致所有視圖被重繪,之后焦點丟失.有人對此問題有建議或解決方法嗎?謝謝.
I have a few edittext within a listview. i have a generic focuslistener on the edittext that updates the value of the data model and also the background of the edittext when focus is lost by calling notifydatachanged . The problem is that if one of the edittext is holding focus, when i touch the next edittext, it gains focus momentarily then loses focus. I suspect it is due to the notifydatachanged method call that is causing all views to be redrawn, after which the focus is lost. Does anyone have a suggestion or work around on the issue? Thanks.
推薦答案
這確實發(fā)生了,因為所有的視圖都被重繪了,所以代表任何過去被聚焦的行的編輯文本現(xiàn)在是一個完全不同的對象.在適配器中設(shè)置一個變量:int currentFocusedRow;
It is indeed happening because all the views are redrawn, so the edit text representing whatever row used to be focused is now a completely different object. Set a variable in your adapter: int currentlyFocusedRow;
在您的適配器的 getView 中:為每個編輯文本添加一個 onFocusChanged 偵聽器,當(dāng)該編輯文本獲得焦點時,設(shè)置 currentFocusedRow = 焦點編輯文本恰好位于的任何行.還將 currentFocusedRow 中的任何編輯文本設(shè)置為專注.
in getView for your adapter: Add an onFocusChanged listener to each edit text and when that edit text gains focus, set currentlyFocusedRow = whatever row the focused edit text happens to be in. Also set any edit text that is in the currentlyFocusedRow to be focused.
這篇關(guān)于listview中的Android edittext失去了對調(diào)用notifydatachanged的關(guān)注的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!