logo
down
shadow

Reason of RecyclerView Not Loading Data


Reason of RecyclerView Not Loading Data

By : Dawn Capria
Date : November 19 2020, 03:01 PM
this will help I tried to create a List with RecyclerView in Android. However, I don't understand why the RecyclerView could not load data properly. I tried to compare my codes with the example available online and I could not tell what is the difference between example codes and my codes. , The problem is here:
code :
  @Override
public int getItemCount() {
    return 0;
}
      @Override
public int getItemCount() {
    return contactList.size();
}


Share : facebook icon twitter icon
RecyclerView scrolling top when loading new data

RecyclerView scrolling top when loading new data


By : Florin
Date : March 29 2020, 07:55 AM
it helps some times I tried solutions posted above but none worked. Helpfully I manage to find some fix. Solution is in 3 magic lines :
code :
 private Parcelable recyclerViewState; 
 recyclerViewState = newsList.getLayoutManager().onSaveInstanceState();
 newsList.getLayoutManager().onRestoreInstanceState(recyclerViewState);
Reason behind (!nextProps.data.loading && this.props.data.loading)

Reason behind (!nextProps.data.loading && this.props.data.loading)


By : Swetha Ts
Date : March 29 2020, 07:55 AM
this will help Your component receives the loading prop from a parent component/store and componentWillRecieveProps fires just before that prop is applied to your component. So from what I gather:
Recyclerview item-height changes after loading data

Recyclerview item-height changes after loading data


By : Sivakumar Avkd
Date : March 29 2020, 07:55 AM
seems to work fine Since we have no idea about the size of text being loaded before it completes, the only option we have is to leave some area reserved for that text.
This can easily be done by making either the TextView or one of it's parent (which is not the parent of known texts) fixed sized.
RecyclerView is not loading data

RecyclerView is not loading data


By : user1954231
Date : March 29 2020, 07:55 AM
help you fix your problem I came across this problem so many times. as notifyDatasetChanged() on adapter does not work as indended.
Just create simple function in recyclerview adapter and call a function when data is available from webcall
code :
public void updateDataset(List<Model> updatedData){
yourListWhichInflateData=updatedData;
notifyDatasetChanged();
}
Loading more data in recyclerview on scroll

Loading more data in recyclerview on scroll


By : Zultor
Date : March 29 2020, 07:55 AM
Any of those help You have to set Progressbar inside the activity's xml where Recyclerview is defined. and loadThumbnail is a function to download thumbnail. it just gives a little delay to scroll down. Now the complete code for the adapter class is as following
code :
public class CamerasAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

private List<MyModel> list;
private Activity mActivity;
private static final int TYPE_VIDEO = 0, TYPE_ADD = 1;
private static final int PAGE_LIMIT = 5;
private int mCurrentLimit = PAGE_LIMIT;
private boolean mIsLoading;
RelativeLayout mLoaderProgress;

public CamerasAdapter(FragmentActivity activity, RelativeLayout loaderLayout) {
    mActivity = activity;
    mLoaderProgress = loaderLayout;
}

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
    View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.li_web_cam_view, viewGroup, false);
    return new CamsViewHolder(itemView);
}

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
    if (mCurrentLimit == (i + 1) && mCurrentLimit <= list.size() && !mIsLoading) {
        mLoaderProgress.setVisibility(View.VISIBLE);
        mIsLoading = true;
        loadThumbnail(0, i + 1);
    } else {
        //do nothing
    }
    ((CamsViewHolder) viewHolder).onBindData(mActivity, list.get(i), i);
    ((CamsViewHolder) viewHolder).emptyView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            itemClickListner.onClick(i, ((CamsViewHolder) viewHolder).tvCamName, list.get(i));
        }
    });
}

private void loadThumbnail(final int count, int position) {
    try {
        if (count > 2 || position >= list.size()) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    mIsLoading = false;
                    mCurrentLimit = mCurrentLimit + PAGE_LIMIT;
                    notifyItemChanged(position - count);
                    mLoaderProgress.setVisibility(View.GONE);
                    return;
                }
            }, 2000);

        } else {
            if (list.get(position) == null) {
                loadThumbnail(count, position + 1);
            } else {
                Glide.with(mActivity).load(list.get(position).getImage_url()).downloadOnly(new SimpleTarget<File>() {
                    @Override
                    public void onResourceReady(File resource, GlideAnimation<? super File> glideAnimation) {
                        loadThumbnail((count + 1), (position + 1));
                    }

                    @Override
                    public void onLoadFailed(Exception e, Drawable errorDrawable) {
                        loadThumbnail((count + 1), (position + 1));
                    }
                });
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        mLoaderProgress.setVisibility(View.GONE);
        mIsLoading = false;
    }

}

@Override
public int getItemCount() {
    return mCurrentLimit <= list.size() ? mCurrentLimit : list.size();
}

public void setData(List<MyModel> dataList) {
    this.list = dataList;
    notifyDataSetChanged();
}

ItemClickListner itemClickListner;

public void setListener(ItemClickListner listener) {
    itemClickListner = listener;
}

ProgressLoadListener progressLoadListener;

public void setProgressLoadListener(ProgressLoadListener listener) {
    progressLoadListener = listener;
}

}
<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:visibility="gone"
    android:layout_height="match_parent"
    android:layout_above="@+id/loader_progress_bar_layout"
    android:background="#f5f5f5"
    android:layout_gravity="center" />

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:id="@+id/loader_progress_bar_layout"
    android:visibility="gone"
    android:background="#fff"
    >
    <ProgressBar
        android:id="@+id/progress_bar_loader"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center" />

</RelativeLayout>
public class Main2Activity extends AppCompatActivity {

RecyclerView recyclerView;
RelativeLayout layoutProgressBar;
CamerasAdapter adapter;
List<Item> itemList;
LinearLayoutManager mLayoutManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);
    layoutProgressBar = findViewById(R.id.loader_progress_bar_layout);
    recyclerView = findViewById(R.id.recycler_view);
    adapter = new CamerasAdapter(getActivity(), loaderLayout);
    mLayoutManager = new LinearLayoutManager(getActivity());
    recyclerView.setLayoutManager(mLayoutManager);
    recyclerView.setAdapter(adapter);

    adapter.setProgressLoadListener(new ProgressLoadListener() {
        @Override
        public void loadProgressBar() {
            layoutProgressBar.setVisibility(View.VISIBLE);
        }
    });
    adapter.setData(setAdaperData());

}

public List<MyModel> setAdaperData(){ 
    List<MyModel> modelList = new ArrayList<>();
    /*addItemsto list*/
    return modelList;

}
}
Related Posts Related Posts :
  • Interrupt CompletableFuture with default value
  • Eclipse - Choosing servers in "Run on server" vs setting "Target Runtime"
  • Spring JPA doesn't validate bean on update
  • How is takeWhile different from filter?
  • Spring Scheduled Cron jobs firing at wrong time
  • JFrame window resizing on every compile. Different results every time
  • Kotlin unresolved reference :add after converting from Java code
  • How to use Neo4j APOC method " apoc.export.csv.query(query,file,config)" in Java program
  • Regex to include all spanish characters and number
  • Parsing and Mapping a JSON Object with Dynamic Properties
  • Which approach to building domain objects in Spring MVC is more correct?
  • Java Long Min and Max not exact as mentioned in docs
  • Selenium opens new tab after SendKeys
  • How to sort a large array of ints?
  • FitNessse Test can not find Fixture
  • Including Signed Libraries in Executable JAR with Maven
  • If and Else statement run on second iteration of while loop
  • Change class of disabled tab on change of dropdown value
  • Junit5 @ParameterizedTest How to pass array as one of parameter
  • Text message not being sent to a list of numbers but is sent when just one number is specified
  • Spring mapped servlet not called in jetty-maven-plugin
  • How to pace the consumption of a sqs queue using spring integration
  • Autowiring Not getting disabled using xml configuration
  • Maze solve and shortest path with Java BFS
  • Spinner updating only on user actions
  • Why are Java rules for protected access such as they are?
  • Modify parameter of method by value in annotation aspectJ
  • How to send sensitive data to a Liferay portlet from outside the Liferay portal
  • Does a server connection stay open if created inside a method?
  • JAR manifest Class-Path, use folder instead of jar
  • How to do a bulk update in Firestore
  • ItemArray.checklist.add() not appending string to ArrayList
  • How to move something on screen without other picture staying there
  • SpringBoot : No matching bean found exception
  • Implementing the Clonable interface, but don't have to override the clone() method
  • how can i get this code to choose a random word once from each array to print a sentence?
  • Static class to get connections from connection pool
  • Unable to start Chrome browser with user profile in Selenium
  • How to pass a object to be created as a parameter for a method in Java?
  • How to retry with hystrix
  • Loading key to KeyStore fails on Android Oreo
  • Spring+Velocity unsuccessful attempts to save object
  • Private constructor in Kotlin
  • Jetty:run fails with NoSuchMethodError with Spring 5
  • Cannot upload my Web Applicartion in Jboss7 EAP7 EAP
  • How to load a certificate from "Credential storage"?
  • Call Genexus procedure stub in Java environment
  • JavaFX clipping produces a 'lottery scratch ticket'-Effect
  • Using DateTimeFormatter on january first cause an invalid year value
  • Get all the output from Watson conversation using java
  • Java unable to open main class and jar file
  • How to override @override method from activity into another class
  • Adding Runtime VM parameters to intellij for Java 9
  • Java IBM MQ Client connected but not getting messages from queue
  • Questions of Tomcat SSL configuration
  • Stale JNLP files for <extension> (since Java 9?)
  • Properly set (system) properties in JUnit 5
  • Spring MVC Model within POST Method is empty
  • VSTS buildagent: Java 9
  • java.lang.NumberFormatException: For input string: "id" for Hibernate
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org