listview中的Android edittext失去了对调用notifydatacha

Android edittext in listview loses focus on calling notifydatachanged(listview中的Android edittext失去了对调用notifydatachanged的关注)

本文介绍了listview中的Android edittext失去了对调用notifydatachanged的关注的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在列表视图中有一些编辑文本.我在edittext上有一个通用的focuslistener,它通过调用notifydatachanged更新数据模型的值以及当焦点丢失时edittext的背景.问题是,如果其中一个编辑文本保持焦点,当我触摸下一个编辑文本时,它会暂时获得焦点然后失去焦点.我怀疑这是由于 notifydatachanged 方法调用导致所有视图被重绘,之后焦点丢失.有人对此问题有建议或解决方法吗?谢谢.

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.

推荐答案

这确实发生了,因为所有的视图都被重绘了,所以代表任何过去被聚焦的行的编辑文本现在是一个完全不同的对象.在适配器中设置一个变量: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 侦听器,当该编辑文本获得焦点时,设置 currentFocusedRow = 焦点编辑文本恰好位于的任何行.还将 currentFocusedRow 中的任何编辑文本设置为专注.

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.

这篇关于listview中的Android edittext失去了对调用notifydatachanged的关注的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:listview中的Android edittext失去了对调用notifydatacha

基础教程推荐