Android onclick加载图库,以位图形式返回图像
我很难从活动返回信息,我对实现的理解不完整。
我想要的是用户能够单击按钮来加载 Android 图库,选择图像,该图像(或可能链接到图像)被转换为位图/可绘制对象,出现在我的活动的 UI 布局中。
我打开了 android 画廊,但没有收到任何回复(我知道为什么,画廊应用程序中没有意图 - 我无权访问它以进行编辑,但我不知道解决方案)
ImageView galleryClick = (ImageView)findViewById(R.id.addgallery);
profilePic = (ImageView)findViewById(R.id.profilepic);
galleryClick.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select Picture"),1);
}
});
我什么希望 onActivityFinished 会在我的手写活动中被调用,但该方法从未被调用(我在其代码
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
// currImageURI is the global variable I'm using to hold the content:// URI of the image
//currImageURI = data.getData();
}
}
}
解决方案中放置了断点?
I am having difficulty returning information from an activity, my understanding of the implementation is incomplete.
What I want is the user to be able to click a button to load up the android gallery, select an image, that image (or link to the image perhaps) is converted to a bitmap/drawable which appears in my activity's UI layout.
I have the android gallery opening but I am not getting any response back from it (I know why, there are no intents in the gallery app - which I dont have access to in order to edit, but I dont know the solution)
ImageView galleryClick = (ImageView)findViewById(R.id.addgallery);
profilePic = (ImageView)findViewById(R.id.profilepic);
galleryClick.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("image/*");
startActivityForResult(Intent.createChooser(intent, "Select Picture"),1);
}
});
What I was hoping was the onActivityFinished would be called in my handwritten activity, but that method is never called (I put a breakpoint in its code
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
if (requestCode == 1) {
// currImageURI is the global variable I'm using to hold the content:// URI of the image
//currImageURI = data.getData();
}
}
}
solutions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我正确理解你的问题,我相信之前在 Stack Overflow 上也有人问过类似的问题。这是我想到的:
获取/挑选以编程方式获取 Android 内置图库应用中的图像
If I understand your question correctly, I believe a similar question has been asked previously on Stack Overflow. Here's the one I'm thinking of:
Get/pick an image from Android's built-in Gallery app programmatically
使用这个:
Use this :