包含在一个Recyclerview从内侧EDITTEXT获取文本 [英] Getting text from inside editText that is contained in a Recyclerview

查看:1246
本文介绍了包含在一个Recyclerview从内侧EDITTEXT获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含一个EditText一个Recyclerview,当按钮是RecyclerView外pssed $ P $,我想检索来自RecyclerView内的每个视图中的文本。不过,我似乎无法找到这样做的最佳方式。我曾尝试使用一个回调,也尝试了外部类来存储数据,但两种方式看起来像他们应该工作,但没有多少运气无论是。什么是歌厅文本出每个的EditText蹦床网上单的,使得它可以是一个添加到阵列或数据库中的最佳实践。

I have a Recyclerview that contains an edittext, when a button is pressed outside the RecyclerView, I would like to retrieve the text from each view inside the RecyclerView. However I can't seem to find the best way to do that. I have tried to use a callback, and also have tried a external class to store the data but both ways seem like they should work but have not had much luck with either. What is the best practice for geting the text out of each edittext indivdual so that it can be a added to an array or database.

推荐答案

在回收视图,列表视图等,有一种观点回收机制,以减少内存消耗。

In recycle view, list view etc, there is a view recycling mechanism to reduce the memory consumption.

所以,简单地通过循环查看孩子的迭代不会给你整个数据。

So simply iterating through recycle view childs won't give you the whole data.

例如是否有回收鉴于10个项目,如果在屏幕上显示5个项目,然后如果你通过循环查看孩子的迭代去,你将只能得到很少的孩子相关的数据,比如6或7。因为别人的观点将被重用。

For example if there are 10 items in recycle view and if 5 items are shown on the screen, then if you go with iterating through the recycle view childs, you will get only data associated with few children, say 6 or 7. Because for others the view will be reused.

所以你的情况,你需要做的是从的EditText模型或bean类保存数据在视图中查看回收重复使用适配器的时候。当点击该按钮,然后就可以把孩子的迭代并获取数据,并再次把这些数据模型或bean类。然后从bean列表中,可以得到整个编辑的数据。

So in your case what you need to do is to save the data from edittext to model or bean class at the time of view reusing in Recycle View adapter. When the button is clicked, then you can iterate through the childs and get the data and put that data again to model or bean class. Then from the bean list you can get the whole edited data.

这篇关于包含在一个Recyclerview从内侧EDITTEXT获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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