Android ListView 中的 EditText

发布于 2024-10-15 04:22:26 字数 344 浏览 2 评论 0原文

我创建了一个自定义数组适配器来绑定包含一些静态文本和可编辑 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一袭水袖舞倾城 2024-10-22 04:22:26

您可以在 ArrayAdapter 中的 EditText 上使用 onEditorAction

mEditText.setOnEditorActionListener(new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
        // Parse parent tree to find position of view
        int position = 0;
        View v = null;
        while (view != v && position < mListView.getChildCount())
            v = mListView.getChildAt(position++);
        // do something
        something(position);
        // do not consume the action
        return false;
}
});

请注意,使用此方法,仅当用户按“时”才会触发事件键盘上有“确定”、“输入”、“完成”等。

You can use onEditorAction on your EditText in your ArrayAdapter:

mEditText.setOnEditorActionListener(new OnEditorActionListener() {
    @Override
    public boolean onEditorAction(TextView view, int actionId, KeyEvent event) {
        // Parse parent tree to find position of view
        int position = 0;
        View v = null;
        while (view != v && position < mListView.getChildCount())
            v = mListView.getChildAt(position++);
        // do something
        something(position);
        // do not consume the action
        return false;
}
});

Note that using this method, you are going to trigger an event only when user press "ok", "enter", "done", etc. on the keyboard.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文