【发布时间】:2014-03-23 09:35:30
【问题描述】:
我正在做一个项目,在该项目中单击 gridview 中的图像会在 ImageView 中打开该图像,我从该网站获得此代码http://www.androidhive.info/2012/02/android-gridview-layout-tutorial/,因此我修改了 FullImageActivity.java 并添加了一个按钮来设置图像作为背景,但每次我点击按钮时,它都会强制关闭我的应用程序,P.S 我也在清单中添加了权限
这是我的代码
package com.example.androidhive;
import java.io.IOException;
import android.app.Activity;
import android.app.WallpaperManager;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
public class FullImageActivity extends Activity {
private WallpaperManager imageView;
@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]);
}
public void setaswall(View view) { // SET AS WALLPAPER BUTTON
// 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();
}
}
};
【问题讨论】:
-
你已经看过logcat了吗?
-
你能知道你的 logcat 是否有任何错误
-
你想要这个项目吗?
-
否,您的 logcat 中出现任何错误
标签: android gridview onclick imageview