从ImageView的获得ID和设置上点击壁纸

从ImageView的获得ID和设置上点击壁纸

本文介绍了从ImageView的获得ID和设置上点击壁纸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建的墙纸应用程序,我停留在同一痘痘问题。
我做了与图像视图和按钮设置为墙纸应用程序。但是有一个问题。当我打开图片,然后点击设置为墙纸按钮,我希望它从中打开图片获取ID和设置图片为wallaper。
这里是我的code

 公共类FullImageActivity延伸活动{
INT toPhone;
ImageAdapter显示;
@覆盖
公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.full_image);
    //获取数据的意图
    意向I = getIntent();    //选择图片ID
    。INT位置= i.getExtras()调用getInt(ID);
    ImageAdapter imageAdapter =新ImageAdapter(本);    ImageView的ImageView的=(ImageView的)findViewById(R.id.full_image_view);
    imageView.setImageResource(imageAdapter.mThumbIds [位置]);    按钮buttonSetWallpaper =(按钮)findViewById(R.id.setwallpaper);
       buttonSetWallpaper.setOnClickListener(新OnClickListener(){        @覆盖
        公共无效的onClick(视图v){
            // TODO自动生成方法存根
            WallpaperManager myWallpaperManager
             = WallpaperManager.getInstance(getApplicationContext());
            尝试{
             myWallpaperManager.setResource(R.drawable.pic_1);
            }赶上(IOException异常五){
             // TODO自动生成catch块
             e.printStackTrace();
            }        }
    });
}


解决方案

我觉得你应该得到的ImageView位图并使用该位图来设置wallpaper.Like这样的: -

  ImageView的ImageView的=(ImageView的)findViewById(R.id.full_image_view);
imageView.setImageResource(imageAdapter.mThumbIds [位置]);按钮buttonSetWallpaper =(按钮)findViewById(R.id.setwallpaper);
   buttonSetWallpaper.setOnClickListener(新OnClickListener(){    @覆盖
    公共无效的onClick(视图v){
        // TODO自动生成方法存根
        WallpaperManager myWallpaperManager
         = WallpaperManager.getInstance(getApplicationContext());
        尝试{
         位图的位图=((BitmapDrawable)imageView.getDrawable())getBitmap();
         如果(位图!= NULL)
         myWallpaperManager.setBitmap(位图);
        }赶上(IOException异常五){
         // TODO自动生成catch块
         e.printStackTrace();
        }    }
});

I am creating wallpaper application and I am stuck at one litle problem.I've made application with image view and button to set as wallpaper. But there is a problem. When I open the picture and click on Set as Wallpaper button I want it to get ID from OPENED picture and set that picture as wallaper.here is my code

public class FullImageActivity extends Activity {
int toPhone;
ImageAdapter display;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.full_image);


    // get intent data
    Intent i = getIntent();

    // Selected image id
    int position = i.getExtras().getInt("id");
    ImageAdapter imageAdapter = new ImageAdapter(this);

    ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
    imageView.setImageResource(imageAdapter.mThumbIds[position]);

    Button buttonSetWallpaper = (Button)findViewById(R.id.setwallpaper);




       buttonSetWallpaper.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            WallpaperManager myWallpaperManager
             = WallpaperManager.getInstance(getApplicationContext());
            try {
             myWallpaperManager.setResource(R.drawable.pic_1);
            } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
            }

        }
    });
}
解决方案

I think you should get the bitmap from imageview and use that bitmap to set wallpaper.Like this:--

ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
imageView.setImageResource(imageAdapter.mThumbIds[position]);

Button buttonSetWallpaper = (Button)findViewById(R.id.setwallpaper);
   buttonSetWallpaper.setOnClickListener(new OnClickListener() {

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        WallpaperManager myWallpaperManager
         = WallpaperManager.getInstance(getApplicationContext());
        try {
         Bitmap bitmap=((BitmapDrawable)imageView.getDrawable()).getBitmap();
         if(bitmap!=null)
         myWallpaperManager.setBitmap(bitmap);
        } catch (IOException e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
        }

    }
});

这篇关于从ImageView的获得ID和设置上点击壁纸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 12:40