Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

android - Is there way to acces every RecyclerViewHolder?

I have a recyclerview with data that changes during the lifecycle of an app, lets say that in my recycler view holders i have an edittext field that comes with populated data but I want user to have access to change that data, is there a way that when the button is pressed i can somehow access all of those textfields at once?

question from:https://stackoverflow.com/questions/65944369/is-there-way-to-acces-every-recyclerviewholder

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Hmm you could keep 2 parallel lists in your recycle view adapter? one that has the main data, the other one is updated whenever the user changes something on an edit text.

Once the user presses the update button, you can just copy the data from list2(with modified data) to list1 (original) and update the recycler view.

for example

inside onBindviewholder()

@Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        // find your edittext to set a listener for text change
       // get the current item from list2 (list2 has same item originally as the original list)
keep updated the list2 data here.

       
    }

on the main activity once the user presses the button you can do

adapter.mainList = new ArrayList<>(adapter.list2)
adapter.notifyDataSetChanged()

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...