所以,我有一个活动,比方说,它PetDetailActivity显示一个带有一些位图的轮播(我用来com.synnapps:carouselview:0.1.5处理我的轮播)。问题是 PetDetailActivity 加载了 0 大小的轮播,这可能图像仍在由线程处理。如何等待Picasso处理完URL,然后将其显示在新的Activity中?
这是 PetDetailActivity 的代码:
import ...
public class PetDetailActivity extends AppCompatActivity {
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pet_detail);
Intent i = getIntent();
Pet targetPet = (Pet)i.getSerializableExtra("PetObject");
ActionBar actionBar = getSupportActionBar();
if(actionBar!=null) actionBar.setDisplayHomeAsUpEnabled(true);
//Creating a BitmapHandler object to download image from URL to Bitmap object using picasso.
BitmapHandler bitmapHandler = new BitmapHandler(targetPet.getCarouselImageUrl());
final ArrayList<Bitmap> petCarouselBitmaps = bitmapHandler.getProcessedBitmap();
//The bitmap is being downloaded in other thread, so the activity is up and
//CarouselView is still empty (petCarouselBitmaps.size() == 0)
//So how to wait the bitmaps is processed, like show a loading screen on the UI?
CarouselView petCarousel = findViewById(R.id.petCarousel);
petCarousel.setPageCount(petCarouselBitmaps.size());
petCarousel.setImageListener(new ImageListener() {
@Override
public void setImageForPosition(int position, ImageView imageView) {
imageView.setImageBitmap(petCarouselBitmaps.get(position));
}
});
}
...
}
小唯快跑啊
凤凰求蛊
相关分类