When I add data to the adapter for RecyclerView to scroll hangs for 1 second, how to solve?

Hi all there is such a markup
<?xml version="1.0" encoding="utf-8"?>
<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="parent" android:layout_height="parent" android:focusableintouchmode="true">
 <com.baoyz.widget.pullrefreshlayout android:layout_width="parent" android:layout_height="parent">
 <scrollview android:id="@+id/scrollView" android:layout_width="parent" android:layout_height="parent">
 <linearlayout android:id="@+id/fragment_main_controller" android:layout_width="parent" android:orientation="vertical" android:layout_height="parent">
</linearlayout></scrollview>
 </com.baoyz.widget.pullrefreshlayout> 
</linearlayout>

I create my own View and throw it in fragment_main_controller then create another LinearLayout(container_recycler_view) you attach it to the fragment_main_controller and dynamically create the adapter and RecyclerView and add it using addView all container_recycler_view
When I load from the network data and begin to insert them (except the first times since all the so far empty), it all starts to hang for a second (when updating the adapter),
hang it starts scrolling
Add new items and update the adapter like this:
int v = adapter.getMyModels().size() - 1;
adapter.getMyModels().addAll(myModelPages.getMyModels());
adapter.notifyItemRangeChanged(v, adapter.getMyModels().size() - v);

(tried notifydatasetchanged same result)

Here is the code of the adapter:

public static class ViewHolderMyModel extends RecyclerView.ViewHolder {
 public ItemMyModelWidget itemMyModelWidget;
 public ViewHolderQuestion(ItemMyModelWidget v) {
super(v);
 itemMyModelWidget = v;
}
}

@Override
 public Adapter.ViewHolderMyModel onCreateViewHolder(ViewGroup parent, int viewType) {
 ItemMyModelWidget itemMyModelWidget = new ItemMyModelWidget(parent.getContext());
 ViewHolderMyModel viewHolder = new ViewHolderMyModel(itemMyModelWidget);
 return viewHolder;
}

@Override
 public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {
 final ViewHolderMyModel viewHolderMyModel = (ViewHolderMyModel) holder; 
 final MyModel model = myModels.get(position);
 /* Paste text in itemMyModelWidget and so on*/
 }

What could be the problem?
That is, I understood that when I update the adapter for some reason they are drawn so if the scroll is not at the bottom it starts to hang as elements are added
June 14th 19 at 18:12
1 answer
June 14th 19 at 18:14
Solution
Can't tell from here what the problem is. At least first get rid of weird things (like dynamic creation recycler, why is it you need? and heaps of some containers).
Well, in this situation, the right to invoke the adapter.notifyItemRangeInserted();
You just parsite this is not mantrade, and this slows down?
what do you mean not maintrance?
I make a request using AsyncTask and in onPostExecute insert the data - nikita.Stracke commented on June 14th 19 at 18:17
Show code - Art_Christians commented on June 14th 19 at 18:20
,
tasks.add(new AsyncTask<void, void, apiresult>() {
@Override
 protected void onPostExecute(APIResult apiResult) {
super.onPostExecute(apiResult);
 MyModels myModels = (MyModels) apiResult.getObject();
 int v = adapter.getMyModels().size() - 1;
adapter.getMyModels().addAll(myModelPages.getMyModels());
 adapter.notifyItemRangeChanged(v, adapter.getMyModels().size() - v);
 //questionAdapter.notifyItemRangeInserted(v, adapter.getMyModels().size());
}

@Override
 protected APIResult doInBackground(Void... params) {
 return API.req();
}
 }.execute());</void>
- nikita.Stracke commented on June 14th 19 at 18:23
what do you say? - nikita.Stracke commented on June 14th 19 at 18:26
anything unclear. The result is not used in fact, just to get the number. It's all strange. In the methods getObject and getMyModels? - Art_Christians commented on June 14th 19 at 18:29
,
Well, see there is a model MyModel, there are properties title description createdAt and so on + images (links to them)
The adapter has an ArrayList of these models (getMyModels to get this ArrayList) I just added to main sheet new MyModel objects
adapter.getMyModels().addAll(myModels);
but this line MyModels myModels = (MyModels) apiResult.getObject(); not confused a lot
MyModels ArrayList = (ArrayList) apiResult.getObject()

Here is the fixed code

tasks.add(new AsyncTask<void, void, apiresult>() {
@Override
 protected void onPostExecute(APIResult apiResult) {
super.onPostExecute(apiResult);
 ArrayList<mymodel> myModels = (ArrayList<mymodel>) apiResult.getObject()
 int v = adapter.getMyModels().size() - 1;
adapter.getMyModels().addAll(myModels);
 adapter.notifyItemRangeChanged(v, adapter.getMyModels().size() - v);
 //questionAdapter.notifyItemRangeInserted(v, adapter.getMyModels().size());
}

@Override
 protected APIResult doInBackground(Void... params) {
 return API.req();
}
 }.execute());</mymodel></mymodel></void>
- nikita.Stracke commented on June 14th 19 at 18:32
I do not know. Somewhere a mistake. Not reciclare. - Art_Christians commented on June 14th 19 at 18:35
and generally because of what can scroll(ScrollView) while adding the data adapter for this ? - nikita.Stracke commented on June 14th 19 at 18:38
last question
I add the adapter 10 items at the start of the fragment
but the screen is visible only to let's say 3
but in the logs this is what
10-09 22:40:49.340 14407-14407/project D/ADAPTER_Q: onCreateViewHolder 0
10-09 22:40:49.340 14407-14407/project D/ADAPTER_Q: onBindViewHolder 0
10-09 22:40:49.415 14407-14407/project D/ADAPTER_Q: onCreateViewHolder 1
10-09 22:40:49.415 14407-14407/project D/ADAPTER_Q: onBindViewHolder 1
10-09 22:40:49.437 14407-14407/project D/ADAPTER_Q: onCreateViewHolder 2
10-09 22:40:49.437 14407-14407/project D/ADAPTER_Q: onBindViewHolder 2
10-09 22:40:49.458 14407-14407/project D/ADAPTER_Q: onCreateViewHolder 3
10-09 22:40:49.458 14407-14407/project D/ADAPTER_Q: onBindViewHolder 3
10-09 22:40:49.480 14407-14407/project D/ADAPTER_Q: onCreateViewHolder 4
10-09 22:40:49.480 14407-14407/project D/ADAPTER_Q: onBindViewHolder 4
10-09 22:40:49.503 14407-14407/project D/ADAPTER_Q: onCreateViewHolder 5
10-09 22:40:49.503 14407-14407/project D/ADAPTER_Q: onBindViewHolder 5
10-09 22:40:49.524 14407-14407/project D/ADAPTER_Q: onCreateViewHolder 6
10-09 22:40:49.524 14407-14407/project D/ADAPTER_Q: onBindViewHolder 6
10-09 22:40:49.546 14407-14407/project D/ADAPTER_Q: onCreateViewHolder 7
10-09 22:40:49.546 14407-14407/project D/ADAPTER_Q: onBindViewHolder 7
10-09 22:40:49.567 14407-14407/project D/ADAPTER_Q: onCreateViewHolder 8
10-09 22:40:49.567 14407-14407/project D/ADAPTER_Q: onBindViewHolder 8
10-09 22:40:49.588 14407-14407/project D/ADAPTER_Q: onCreateViewHolder 9
10-09 22:40:49.588 14407-14407/project D/ADAPTER_Q: onBindViewHolder 9


Why? he only need to create only 3 holder for the idea and then the rest when scrolling - nikita.Stracke commented on June 14th 19 at 18:41
hmm. Yes, you should. Maybe 4, but not all 10. Weird. - Art_Christians commented on June 14th 19 at 18:44
,
here is how I create RecyclerView
RecyclerView recyclerView = new RecyclerView(activity);
RelativeLayout.LayoutParams params = new 
 RelativeLayout.LayoutParams(ViewGroup.LayoutParams.PARENT, 
ViewGroup.LayoutParams.Wrap content);
recyclerView.setLayoutParams(params);
recyclerView.setLayoutManager(llm);
recyclerView.setNestedScrollingEnabled(false); 
ModelAdapter modelAdapter = new ModelAdapter(models) 
recyclerView.setHasFixedSize(false);
recyclerView.setAdapter(modelAdapter);
recyclerView.addItemDecoration(new VerticalSpaceItemDecoration((int) Convert.convertDpToPixel(4)));
container.addView(recyclerView);

Maybe the problem is here? Maybe I'm doing something not right - nikita.Stracke commented on June 14th 19 at 18:47
LayoutParams.Wrap content. He relayout you doing on each element. Of course it's the brakes. Especially in RelativeLayout'e. Well I just asked - what do you do that? - Art_Christians commented on June 14th 19 at 18:50
,
removed these lines
RelativeLayout.LayoutParams params = new 
 RelativeLayout.LayoutParams(ViewGroup.LayoutParams.PARENT, 
ViewGroup.LayoutParams.Wrap content);
recyclerView.setLayoutParams(params);

Still, the program automatically generates all 10/10 holders although the screen 3-4
container is a LinearLayout
LinearLayout linearLayout = new LinearLayout(getActivity());
linearLayout.setOrientation(LinearLayout.VERTICAL);
- nikita.Stracke commented on June 14th 19 at 18:53
I think the problem is due to the fact that recyclerView in a ScrollView and scroll from there on all the elements works so he draws and how to fix XS - nikita.Stracke commented on June 14th 19 at 18:56
get scrollview get all this obscurantism with linearlayout. Do not make the view function from the code. - Art_Christians commented on June 14th 19 at 18:59
okay, what if I need to shove their components ? what type of header
I need to get in your tabWidget to add and when you click on any tab in the center of the fragment a appears indicator download [its also view]
and how is this done ? but very necessary - nikita.Stracke commented on June 14th 19 at 19:02
all this markup stuff, what's the problem? - Art_Christians commented on June 14th 19 at 19:05
well see there is my element then it is followed with a recyclerView, that is to solicit will be only a recyclerView and I need to tab (a component of) the above scrolls all as one in one word
and then slapped the download(progress bar) in the center of the fragment, then? at the start of the fragment and loading the first data - nikita.Stracke commented on June 14th 19 at 19:08
, decision 1(forehead) - make tab another element recycler. Well comes with adapter delegates. Solution 2 - try to use CoordinatorLayout.

Progress on the center - easy. Push it and the main content in the FrameLayout in the correct order and to center. Hide/show with visibility. - Art_Christians commented on June 14th 19 at 19:11
,
"Progress on the center - easy. Push it and the main content in the FrameLayout in the correct order and to center. Hide/show with visibility."
and you can't bring an example of all the markup as it should be right the FrameLayout for the Progres bar in the center of the fragment is very necessary if you certainly not difficult - nikita.Stracke commented on June 14th 19 at 19:14
I just need when a customer clicks on any there tabwidget to this tab remained and appeared view (the progress bar in the center) to almost the whole screen =] to himself, tabwidget not hidden - nikita.Stracke commented on June 14th 19 at 19:17
,
<framelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap content" android:layout_height="wrap content">

 <view android:id="@+id/content" android:layout_width="56dp" android:layout_height="56dp" android:background="#f00">

 <view android:id="@+id/progress" android:layout_width="24dp" android:layout_height="24dp" android:layout_gravity="center" android:background="#0f0">

</view></view></framelayout>
- Art_Christians commented on June 14th 19 at 19:20
I didn't understand what you hockey to do. What you're describing is severe frustration for the user. So the tabs are not used in Android. Enivey, it can be done purely on reciclare. - Art_Christians commented on June 14th 19 at 19:23
,
The client includes a fragment appears download of is a circle spinning in the center of the fragment
then when the data from the server came, I create a tab (a) there are three points, for example, But I
When a client clicks on any of the tabs, say B, the tab remains in place but at the bottom there is a download size of width but height parent: parent - tab.getHeight(); that is, ProgressBar to go below tabwidget
When the data came from the server, this progress bar is removed or hidden and is populated again recyclerView - nikita.Stracke commented on June 14th 19 at 19:26

Find more questions by tags AndroidProgramming