Home > Mobile >  RecycleView partial refresh
RecycleView partial refresh

Time:10-10

Novice is doing a memo to learning android

After returning to create a new entry to mainActivity refresh display properly, the problem is that once again, click on the entry changes after return, show is initially after the new state, and then modify the interface to switch back and forth with the list of interface entries state between the initial state and normal state repeatedly switch,,,

This is to create a new empty entry after the state of the


This is click on the switching activity after modified


Modify the state of the return, and then can follow the activity of the entry form constantly switching between above and below conversion


That is, list the activity every time suspended after entry state switching between normal and abnormal, and whether RecycleView reuse pan,
We had several days, can only ask for help, the following is the refresh method code:
/* *
* update interface
*/
Private void updateUI () {
MemoryLab MemoryLab=MemoryLab. Get (getActivity ());//create a singleton object MemoryLab
List Memories.=memoryLab getMemories ();//get the Memory list
If (memories. The size ()!=0) {
MNoOneTextView. SetVisibility (View. GONE);//set the data for empty interface hint view
}
If (mAdapter==null) {
MAdapter=new MemoryAdapter (memories);//this list of initialization mAdapter
MAdapter. SetHasStableIds (true);
MMemoryRecyclerView. SetAdapter (mAdapter);//will mMemoryRecyclerView associated with mAdapter
} else {
MAdapter. NotifyItemChanged (mposition);
}
}

This is custom Adapter class overriding methods:
@ Override
Public void onBindViewHolder (@ NonNull MemoryHolder holder, final int position) {
The Memory of the Memory=mMemories. Get (position);
Holder. The bind (memory);
}

@ Override
Public int getItemCount () {
Return mMemories. The size ();
}

@ Override
Public int getItemViewType (int position) {
Return the position;
}
@ Override
Public long getItemId (int position) {
Return the position;
}

This is custom ViewHolder class of the bind () method:
/* *
* always call the bind (Memory) method to display each Memory
*
* @ param memory
*/
Public void bind the Memory Memory) {
MMemory=memory;
MTitleCheckBox. SetText (" "+ mMemory getTitle ());
SetTime (mMemory getDate ());//set the title and time

MTitleCheckBox. SetChecked (mMemory isSolved ());

MTitleCheckBox. SetOnClickListener (new CompoundButton. An OnClickListener () {
@ Override
Public void onClick (View View) {
MMemory setSolved (! MMemory. IsSolved ());
}
});
}

CodePudding user response:

Where is called updateUI ()?

CodePudding user response:

reference m - 1/f, oj response:
where call updateUI ()?

 in fragments onCreateView () and onResume () method in

CodePudding user response:

List Memories.=memoryLab getMemories ()
MAdapter=new MemoryAdapter (memories);
These two sentences have a question, your memories into a new, but are you adapter to keep the remains of the old (Java everything reference)
The novice blog has explained in detail: https://blog.csdn.net/weimingjue/article/details/87921494
Common problem is your problem, it is recommended that all finished

CodePudding user response:

And you can change because for the first time go adapter==null logic

CodePudding user response:

reference 3 floor wang can reply:
List Memories.=memoryLab getMemories ()
MAdapter=new MemoryAdapter (memories);
These two sentences have a question, your memories into a new, but are you adapter to keep the remains of the old (Java everything reference)
The novice blog has explained in detail: https://blog.csdn.net/weimingjue/article/details/87921494
Common problem is your problem, it is recommended that all watching

Thank you, I tried to add an adapter setMemories () method to save the memories again, or not,,
In addition to ask you, is every change reference object data model layer, the object of reference should not have been in the update,,

Call notifyitemchanged method is not only for the first time will refresh, is every refresh variable (conversion) between normal and abnormal

Notifydatasetchanged method is to refresh every time will only refresh the last entry,,

Now I can only use the adapter before each time to refresh=null stupid, can not be real-time brush, new,

I will carefully study your new blog!

CodePudding user response:

Blame I didn't watch carefully, you memoryLab is a singleton, memoryLab. GetMemories () it is also the same object,

GetItemViewType deleted, it is a variety of UI patterns return can search "listview items more directly, completely useless, you here if you return so no reuse

Additional code does not need to write in the viewholder directly in onBindViewHolder written line (mMemory delete directly, to the final) written, that may have reuse problem,

The other is not much said,

Given the code you see style switching back and forth will appear problem, if is only 1 entry should be no problem,

It is recommended to use the debug mode, how to search the debug,

Hit two first breakpoint:
1. Where you modify the break point, take a look at whether modifying right
. 2. In your "mTitleCheckBox setText" this line on breakpoints, every time when switching to check the "memory" is inside you the desired value,

CodePudding user response:

My guess is that when you modify changed back to the default value, the debug take a closer look

CodePudding user response:

reference 7 floor wang can reply:
I guess is changed back to the default value, when you modify the debug a closer look at

Is not the problem of data, and still not solve, and according to the book (android programming guide) authority to do, and so the first can't, have been to this problem, and then to learn after the first, after all, subject to slowly,,

Very thank you for your help to guide  ??????
  • Related