java - 如何关闭进度条
问题描述
我在 Bindviewholder 中为我的片段使用progressDialog,它会在其中加载,直到图像和文本没有从在线填充。但是我希望我的进度对话框在全部加载后关闭或隐藏,但我确实将我的进度对话框放在下面
youTubeThumbnailLoader.release();
但仍然没有发布进度对话框并且它是可见的。如何隐藏进度对话框。请帮忙
下面是我的代码
public class YoutubeVideoAdapter extends RecyclerView.Adapter<YoutubeViewHolder> {
private static final String TAG = YoutubeVideoAdapter.class.getSimpleName();
ProgressDialog progressDialog;
private Context context;
private ArrayList<YoutubeVideoModel> youtubeVideoModelArrayList;
public YoutubeVideoAdapter(Context context, ArrayList<YoutubeVideoModel> youtubeVideoModelArrayList) {
this.context = context;
this.youtubeVideoModelArrayList = youtubeVideoModelArrayList;
}
@Override
public YoutubeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.youtube_video_custom_layout, parent, false);
return new YoutubeViewHolder(view);
}
@Override
public void onBindViewHolder(YoutubeViewHolder holder, final int position) {
progressDialog = new ProgressDialog(context);
progressDialog.setMessage("Please wait..."); // Setting Message
progressDialog.setTitle("Loading"); // Setting Title
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); // Progress Dialog Style Spinner
progressDialog.show(); // Display Progress Dialog
progressDialog.setCancelable(false);
final YoutubeVideoModel youtubeVideoModel = youtubeVideoModelArrayList.get(position);
holder.videoTitle.setText(youtubeVideoModel.getTitle());
holder.videoDuration.setText(youtubeVideoModel.getDuration());
/* initialize the thumbnail image view , we need to pass Developer Key */
holder.videoThumbnailImageView.initialize(Constants.DEVELOPER_KEY, new YouTubeThumbnailView.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubeThumbnailView youTubeThumbnailView, final YouTubeThumbnailLoader youTubeThumbnailLoader) {
//when initialization is sucess, set the video id to thumbnail to load
youTubeThumbnailLoader.setVideo(youtubeVideoModel.getVideoId());
youTubeThumbnailLoader.setOnThumbnailLoadedListener(new YouTubeThumbnailLoader.OnThumbnailLoadedListener() {
@Override
public void onThumbnailLoaded(YouTubeThumbnailView youTubeThumbnailView, String s) {
//when thumbnail loaded successfully release the thumbnail loader as we are showing thumbnail in adapter
youTubeThumbnailLoader.release();
progressDialog.dismiss();
}
@Override
public void onThumbnailError(YouTubeThumbnailView youTubeThumbnailView, YouTubeThumbnailLoader.ErrorReason errorReason) {
//print or show error when thumbnail load failed
Log.e(TAG, "Youtube Thumbnail Error");
}
});
}
@Override
public void onInitializationFailure(YouTubeThumbnailView youTubeThumbnailView, YouTubeInitializationResult youTubeInitializationResult) {
//print or show error when initialization failed
Log.e(TAG, "Youtube Initialization Failure");
}
});
}
@Override
public int getItemCount() {
return youtubeVideoModelArrayList != null ? youtubeVideoModelArrayList.size() : 0;
}
}
提前致谢。
解决方案
Your question states that you are using progress bar but your code contains progress dialog , both of them are different.To dismiss the progress dialog you need to call the dismiss method as
progressDialog.dismiss();
推荐阅读
- r - 创建我自己的排序函数时发生错误参数的长度为零
- snmp - Snmp 陷阱接收器作为 Apache Nifi 中的自定义处理器
- codeblocks - 我的代码块 ide 不工作。显示空白页?
- javascript - 如何访问 Json 对象中的属性类?
- stripe-payments - Python + Stripe.js 支付集成给出错误 Invalid payment_page id
- sql - 获取删除的列数
- unity3d - 当碰撞体实际上没有接触时,角色似乎正在碰撞...... - Unity Collision
- python - 回归的 fit() 和 predict() 方法中的逻辑
- css - 如何阻止浮动图像下的文本流动
- scala - 使用现有实例中的值干净地创建类型的新实例