我有一个小问题。
代码目标:单击打开相机的图像视图,然后在获取图片后更改图像视图。 imageview不是照片的缩略图。
问题:imageview不刷新。
我尝试了什么:Android imageView Switching Problem, Changing ImageView on button click, ImageView onClickListener changing the image source (不能使用viewSwitcher b / c有两种以上的可能视图组合), how to change the background or the image source when a clickable imageview in android is clicked?
我的代码:
public class CacTestActivity extends Activity {
private static final int CAMERA_PIC_REQUEST = 2500;
private Bitmap bmp;
private ImageView ivPic;
private Thread thread;
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.cactest);
ivPic = (ImageView) findViewById(R.id.imgCacSetPhoto);
ivPic.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
try {
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA_PIC_REQUEST);
} catch (Exception e) {
}
}
});
thread = new Thread(){
@Override
public void run(){
ivPic = (ImageView) findViewById(R.id.imgCacSetPhoto);
ivPic.setImageResource(R.drawable.takephotoyes);
ivPic.invalidate();
}
};
}
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (getResources().getConfiguration().orientation != Configuration.ORIENTATION_PORTRAIT){
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
if (resultCode == RESULT_OK){
if (requestCode == CAMERA_PIC_REQUEST){
//If getting pic bitmap is successful, then change imageview source
//thread.start(); //Does not work
}
}
}
}
此问题之前已被多次询问,但经过多次搜索后我还没有找到解决方案。我错过了什么?感谢
答案 0 :(得分:0)
确保Eclipse中项目属性中的目标Android版本和清单中的targetSdk匹配。