【发布时间】:2017-08-19 11:01:15
【问题描述】:
我的片段中有四个progress,我在onActivityResult 中定义它们,例如:
if (requestCode == GALLERY_IMAGE1 && resultCode == Activity.RESULT_OK) {
ProgressBar progress = view.findViewById(R.id.progressBar1);
final Uri imageUri = data.getData();
InputStream imageStream = null;
try {
imageStream = getActivity().getContentResolver().openInputStream(imageUri);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
final Bitmap selectedImage = BitmapFactory.decodeStream(imageStream);
bitmap = selectedImage;
image1.setImageBitmap(bitmap);
Log.d(TAG, "onActivityResult: " + progress.getVisibility());
editPhoto("imageName1", progress);
}
if (requestCode == GALLERY_IMAGE2 && resultCode == Activity.RESULT_OK) {
ProgressBar progress = view.findViewById(R.id.progressBar2);
/* bunch of code */
editPhoto("imageName2", progress);
}
在我的日志行中:Log.d(TAG, "onActivityResult: " + progress.getVisibility()); 我得到了 0 值,这意味着 GONE。
当我尝试让它在我的 editPhoto 方法中可见时:
private void editPhoto(final String imagePosition, final ProgressBar progress) {
progress.setVisibility(View.VISIBLE);
Log.d(TAG, "progress: " + progress.getVisibility());
/* bunch of code */
}
我的进度不可见,在我的日志行 Log.d(TAG, "progress: " + progress.getVisibility()); 我得到与上面相同的值 0。
我在这里做错了什么?
【问题讨论】:
-
您必须在 onActivityResult 中定义和声明进度,即本地,您必须在 Fragment 的顶部定义进度全局,然后您才能全局访问它
-
@YogeshMane 我的代码有什么问题?
-
downvoter 你能解释一下为什么对我的问题投反对票吗?
-
在 Fragment 之上声明 ProgressBar。它们超出了范围。
-
@MikeM。谢谢,你是对的,这似乎是我的观点问题,我认为图像涵盖了进展。我会检查的。
标签: java android android-progressbar onactivityresult