如何正确处理一个ListView里面的Andr​​oid的EditText输入? [英] How to correctly handle Android EditText input inside a ListView?

查看:108
本文介绍了如何正确处理一个ListView里面的Andr​​oid的EditText输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序有一个活动,一个的SortedMap 内部添加/删除/编辑记录。该活动是作为 ListActivity 的延伸。我已经实现自定义的 ArrayAdapter 的藏品。

In my application I have an activity to add/remove/edit records inside a SortedMap. The activity is implemented as an extension of ListActivity. I have implemented custom ArrayAdapter for the collection items.

每个的ListView 项目(相当于一个潜在的纪录),包括的TextView S,的EditText S和A 按钮删除的记录本身。布局大致如下:

Every ListView item (which corresponds to an underlying record) consists of TextViews, EditTexts, and a Button to delete the record itself. The layout is roughly as follows:

ListView
----------------------------------------------------
[TextView] [EditText] [TextView] [EditText] [Button]
----------------------------------------------------
[TextView] [EditText] [TextView] [EditText] [Button]

我的目标是处理输入用户键入的的EditText 取值一旦用户完成编辑后,即当用户已经从<$ C导航离开$ C>的EditText 或用户pssed回解雇屏幕键盘$ P $。

My goal is to process the input a user types to the EditTexts as soon as the user finished editing, i.e. when the user has navigate away from the EditText or the user has pressed back to dismiss the onscreen keyboard.

我试图通过处理 onFocusChanged 实现这一点,处理文本中的的EditText 可见。然而,这种方法并不尽如人意, onFocusChanged 方法被调用非常频繁,随意,甚至是未选和放大器;未经编辑的EditText 秒。这可能是由于这篇文章在Android上的博客的StackOverflow问题

I have tried implementing this by handling onFocusChanged, to process the text visible in the EditText. However this method is not working well, onFocusChanged method is called very often and randomly, even for unselected & unedited EditTexts. This is probably due to this article on Android Blog from this StackOverflow question.

有没有更好的方式来做到这一点?

Is there a better way to do this?

推荐答案

的TextView ,其中的EditText 延伸,包括该方法公共无效addTextChangedListener(TextWatcher观察者),可能对你有用。

TextView, which EditText extends, includes the method public void addTextChangedListener (TextWatcher watcher) that may be useful to you.

我以前没有使用过它,但它看起来这将随时调用用户编辑的TextView 键,那么你可以在每次改变时间处理它。这可能会导致大量的开销,如果它被称为每用户删除或添加字符的时间,但它可能是最简单的解决方案。

I have not used it before but it seems like this would be called anytime the user edits the TextView and then you could process it every time it changes. This may cause a lot of overhead if it is called every time a user deletes or adds a character, but it may be the easiest solution.

这篇关于如何正确处理一个ListView里面的Andr​​oid的EditText输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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