'Set loading view on recyclerview and remove after data is loaded
I want to have a loading icon that is displayed on top of where a RecyclerView would be, and disappear once the data is finished loading
Can anyone help me out?
I have the code which shows pdf files of phone storage on recyclerview but pdf files finding function takes some time so recyclerview take time in set view So i want to add loading feature.
My XML:
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
My Java Code:
public class MainActivity extends AppCompatActivity{
RecyclerView recyclerView;
ProgressBar progressBar;
ArrayList<File> arrayList;
RecyclerViewAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
recyclerView = findViewById(R.id.recycler_view);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
arrayList = findpdf(Environment.getExternalStoragePublicDirectory("/"));
adapter = new RecyclerViewAdapter(this, arrayList);
recyclerView.setAdapter(adapter);
}
public ArrayList<File> findpdf(File folder){
ArrayList<File> arrayList = new ArrayList<>();
try {
File[] files = folder.listFiles();
for (File file: files){
if (file.isDirectory() && !file.isHidden()){
arrayList.addAll(findpdf(file));
}
else {
if (file.getName().endsWith(".pdf")){
arrayList.add(file);
}
}
}
}catch (Exception e){
e.printStackTrace();
}
return arrayList;
}
Please Help! I want loading feature while finding pdf function and recyclerview load data.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
