安卓:编程选择GALLARY图像 [英] Android: programatically select Gallary image

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

问题描述

我在我的应用程序,它是工作的罚款图库视图。当在库项目点击,我在ImageView的显示完整的图像。当第一次加载的活动,我想以编程方式显示在完整图像的ImageView的第一形象,使用户不必点击图库中的第一项。

任何人可以帮助我吗?

谢谢,
Nehatha

---编辑----

 公共无效的onCreate(){
//其他code    GA =(图库论坛)findViewById(R.id.photo_gallary);
    ImageView的=(ImageView的)findViewById(R.id.gallary__full_img);    ga.setOnItemClickListener(新OnItemClickListener(){
        @覆盖
        公共无效onItemClick(适配器视图<>为arg0,ARG1观,诠释ARG2,
                长ARG3){
            displayFullImg(ARG2);
        }
    });
ga.setAdapter(新ImageAdapter(本));
ga.setSelection(0);
} //的onCreate私人无效displayFullImg(INT ARG2){
  项目项目= pics.get(ARG2);
  字符串URL = item.getImageUri();
  imageView.setImageBitmap(URL);
}


解决方案

您可以直接使用

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

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.

Can anybody help me?

Thanks, Nehatha

--- 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);
}

解决方案

You can use directly

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

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

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