Android edittext in listview loses focus on calling notifydatachanged

后端 未结 5 1755
清酒与你
清酒与你 2020-12-15 18:05

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

5条回答
  •  难免孤独
    2020-12-15 18:39

    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;

    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.

提交回复
热议问题