简体   繁体   English

recyclerview 中的回收编辑文本

[英]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 个,当用户滚动时,它将回收和重用它们。

  1. EditText A编辑文本 A
  2. Edittext B编辑文本 B
  3. EditText C (recycled) EditText C(回收)
  4. EditText D (recycled) EditText D(回收)
  5. .... ....

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.我认为您可能需要的是RecyclerViewOnChildAttachStateChangeListener功能。 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.

相关问题 从Recyclerview中包含的editText内部获取文本 - Getting text from inside editText that is contained in a Recyclerview 管理如何在 RecyclerView 中回收视图 - Manage how views are recycled in RecyclerView 从RecyclerView到EdiTtext - RecyclerView to EdiTtext Android-Studio,CustomDialog焦点问题内RecyclerView内的EditText - Android-Studio, EditText inside RecyclerView inside CustomDialog focus issue Android Kotlin - RecyclerView - 获取回收项目的 position - Android Kotlin - RecyclerView - get position of recycled item 在RecyclerView的onBindViewHolder方法中将文本设置为EditText时出错 - Error setting text to EditText inside RecyclerView's onBindViewHolder method 'RecyclerView:没有连接适配器; 在父布局中将 RecyclerView 与 EditText 一起嵌套时跳过布局错误 - 'RecyclerView: No adapter attached; skipping layout' error when nesting RecyclerView alongside EditText inside parent layout 尽管回收了所有视图,还是调用了Recyclerview onCreateViewHolder? - Recyclerview onCreateViewHolder being called despite all views being recycled? 当 EditText 不在焦点时,Recyclerview 消失 - Recyclerview disappers when EditText not in Focus 使用EditText在RecyclerView中编辑重复项 - Editing duplicated item in RecyclerView with EditText
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM