gpt4 book ai didi

java - 如何在 Firebase RecyclerView 中添加加载进度条

转载 作者:行者123 更新时间:2023-12-02 01:22:09 26 4
gpt4 key购买 nike

我正在开发一个 Android 应用 该应用使用 FirebaseRecyclerAdapter 从 Firebase 获取数据我需要实现 ProgressBar在那Recyler View .

How to add RrogressBar in RecyclerView before the data is loaded..and after the data is loaded the loading screen need to be Dismiss

代码:

protected void onStart() {
super.onStart();

DatabaseReference reference = FirebaseDatabase.getInstance().getReference().child("Vacancy");

FirebaseRecyclerOptions<VacancyModel> options = new FirebaseRecyclerOptions.Builder<VacancyModel>()
.setQuery(reference.orderByChild("companyname"), VacancyModel.class)
.build();


FirebaseRecyclerAdapter<VacancyModel, VacancyViewHolder> adapter =
new FirebaseRecyclerAdapter<VacancyModel, VacancyViewHolder>(options) {

@Override
protected void onBindViewHolder(@NonNull VacancyViewHolder holder, int position, @NonNull final VacancyModel model) {

jprog.setVisibility(View.VISIBLE);


holder.vacompany_name.setText(model.getCompanyname());
holder.vajob_type.setText("Job Title: " + model.getJob_title());
holder.vatiming.setText(model.getTiming());
holder.vatotal_vacancy.setText("Total Vacancy: " +model.getTotal_vacancy());
holder.vasp.setText(model.getS_p());
holder.vaexpected_vasalary.setText("Expected Salary: " +model.getExpexted_salary());
holder.vaarea.setText("Area: " +model.getPincode());
holder.vaphone_number.setText("Contact Number: " +model.getContact_number());



holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {


Intent intent = new Intent(Home.this, VacancyViewActivity.class);
intent.putExtra("pid", model.getCompanyID());
startActivity(intent);

}

});
}


@NonNull
@Override
public VacancyViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.vacancy_list_item, viewGroup, false);
VacancyViewHolder holder = new VacancyViewHolder(view);
return holder;
}

};

recyclerView.setAdapter(adapter);
adapter.startListening();


}

最佳答案

由于您使用的是 FirebaseRecyclerAdapter,因此您可以重写适配器类中的 onDataChanged() 方法。因此,创建一个新的 ProgressBar 对象并开始在 onCreate() 方法中显示它,或者如果需要,您可以将其直接添加到 .XML 文件中。最后在您的适配器类中,使用以下代码行:

@Override
public void onDataChanged() {
if (progressBar != null) {
progressBar.setVisibility(View.GONE);
}
}

关于java - 如何在 Firebase RecyclerView 中添加加载进度条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57507615/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com