[英]recycled edittext inside recyclerview
With RecyclerView, the off-screen EditTexts will be recycled.使用 RecyclerView,屏幕外的 EditTexts 将被回收。 For example, if we have a list of 200 items, and it shows 2 items at one time, we will only ever have 2 EditText.
例如,如果我们有一个包含 200 个项目的列表,并且一次显示 2 个项目,那么我们将只有 2 个 EditText。 They will reuse the higher EditText for the lower elements.
他们将为较低的元素重用较高的 EditText。
For example, here is a list that contains EditText showing only 2 at a time, and as the user scrolls, it will recycle and reuse them.例如,这里有一个包含 EditText 的列表,一次只显示 2 个,当用户滚动时,它将回收和重用它们。
This means we cannot just loop over all the elements later and get the values, as they don't store their values.这意味着我们不能稍后循环遍历所有元素并获取值,因为它们不存储它们的值。
So, what i am asking is that is there anyway to loop over all the items and get there values even the recycled ones and save them to firebase所以,我要问的是无论如何循环遍历所有项目并获得甚至回收的价值并将它们保存到firebase
EDIT: I have a recyclerview with an edit text inside it the user enter numbers inside edit text and when he click save button a for loop iterate over all the recyclerview edit text and save data to Firebase编辑:我有一个带有编辑文本的 recyclerview,用户在编辑文本中输入数字,当他单击保存按钮时,for 循环遍历所有 recyclerview 编辑文本并将数据保存到 Firebase
this is my fragment class这是我的片段类
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.purchases_list_activity, container, false);
mItem = new ArrayList<>();
mAdapter = new PurchasesAdapter(getContext(), mItem, this);
re = view.findViewById(R.id.itemsPListView);
re.setLayoutManager(new LinearLayoutManager(getActivity()));
re.setAdapter(mAdapter);
fab = view.findViewById(R.id.fab_purchases);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for (int i = 0; i < mItem.size(); i++) {
final ItemsAdapter mylist = mItem.get(i);
View childView = re.getChildAt(i);
final EditText Qty = childView.findViewById(R.id.itemNewPcs);
final String qty = Qty.getText().toString();
Toast.makeText(getContext(),qty+"",Toast.LENGTH_LONG).show();
..
}
I think that what you might need is the RecyclerView
's OnChildAttachStateChangeListener
functionality.我认为您可能需要的是
RecyclerView
的OnChildAttachStateChangeListener
功能。 Basically, you implement your own class that implements the OnChildAttachStateChangeListener
interface.基本上,您实现自己的类来实现
OnChildAttachStateChangeListener
接口。 Specifically, the implement the onChildViewAttachedToWindow
method to do save to Firebase or add to a list that can be added to Firebase later - basically whatever you need.具体来说,实现
onChildViewAttachedToWindow
方法以保存到 Firebase 或添加到稍后可以添加到 Firebase 的列表中 - 基本上是您需要的任何内容。 You just attach your custom listener via the addOnChildAttachStateChangeListener()
method.您只需通过
addOnChildAttachStateChangeListener()
方法附加您的自定义侦听器。
Hope that helps.希望有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.