Android:以编程方式选择Gallary图片 [英] Android: programmatically select Gallary image

查看:113
本文介绍了Android:以编程方式选择Gallary图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个Gallery视图,可以正常工作.当单击Gallery项目时,我正在ImageView中显示完整图像.首次加载活动时,我想以编程方式在完整图像的ImageView中显示第一张图像,这样用户不必单击图库中的第一项.

I have a Gallery view in my application which is working fine. When clicking on a Gallery item, I'm displaying the full image in an ImageView. When the activity is first loaded, I want to display the first image in the full image's ImageView programmatically, so that the user doesn't have to click the first item in the Gallery.

---编辑----

--- Edit ----

public void onCreate() {
//other code

    ga = (Gallery)findViewById(R.id.photo_gallary);
    imageView = (ImageView)findViewById(R.id.gallary__full_img);

    ga.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            displayFullImg(arg2);               
        }           
    });


ga.setAdapter(new ImageAdapter(this));
ga.setSelection(0);
}//onCreate

private void displayFullImg(int arg2){
  Item item = pics.get(arg2);
  String url = item.getImageUri();
  imageView.setImageBitmap(url);
}

推荐答案

您可以直接使用

imageView.setImageBitmap(pics.get(0).getImageUri());

这篇关于Android:以编程方式选择Gallary图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆