Android ListView 中的 EditText
我创建了一个自定义数组适配器来绑定包含一些静态文本和可编辑 EditText 的自定义行。我正在尝试注册,以便在用户更改编辑文本中的文本时收到通知,并在收到通知以确定修改后的 EditText 对应的 ArrayList 行时收到通知。
过去,对于其他类型的视图(例如 Spinner),我可以简单地将对父视图的引用和行号放入 Spinner 视图的标记中。然后,当我收到值更改的通知时,我读取标签以确定如何将其关联回主 ArrayList。
注册以获取 EditText 更改通知的问题是,您不会返回视图,而是获得 TextWatcher,并且我无法关联回父视图或 ArrayList 行。
在这种情况下您需要使用什么技术?
I have created a custom Array Adapter to bind a custom row that contains some static text and an editable EditText. I am trying to register to be notified when the user changes the text within the edit text and when notified to determine which ArrayList row the modified EditText corresponds to.
In the past with other types of views such as a Spinner I could simply put a reference to the parent view and the row number into the tag for the Spinner view. And then when I was notified that the value changed I read the tag to determine how to correlate it back to the master ArrayList.
The problem with registering to be notifed with an EditText change is that you do not get back a view but instead get a TextWatcher and I have no way to correlate back to the parent view or ArrayList row.
What is the technique that you need to use in this circumstance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在
ArrayAdapter
中的EditText
上使用onEditorAction
:请注意,使用此方法,仅当用户按“时”才会触发事件键盘上有“确定”、“输入”、“完成”等。
You can use
onEditorAction
on yourEditText
in yourArrayAdapter
:Note that using this method, you are going to trigger an event only when user press "ok", "enter", "done", etc. on the keyboard.