在列表视图的Andr​​oid的EditText失去焦点的要求notifydatachanged [英] Android edittext in listview loses focus on calling notifydatachanged

查看:525
本文介绍了在列表视图的Andr​​oid的EditText失去焦点的要求notifydatachanged的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表视图中的几个的EditText。我有一个更新的数据模型的价值,也是的EditText的背景时,重点是通过调用notifydatachanged失去的EditText一个通用的FocusListener。问题是,如果的EditText之一是保持专注,当我触碰下一个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.

推荐答案

它确实发生了,因为所有的意见都重新绘制,所以无论行用于集中编辑的文本再presenting现在是一个完全不同的对象。在您的适配器设置一个变量:int currentlyFocusedRow;

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侦听器,每个编辑的文本和当编辑文本获得焦点,设置currentlyFocusedRow =无论行聚焦编辑文本恰好是在另外设置的任何修改文本在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.

这篇关于在列表视图的Andr​​oid的EditText失去焦点的要求notifydatachanged的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆