如何从android画廊获取子项目?
我想从图库中获取图像。为此我使用了
View v= mGallery.childAt(index);
ImageView img = (ImageView) v.findViewById(R.id.img);
但有时如果索引图像在此时不可见
空指针异常。
如何从图库中获取不可见的图像?
I want to get the image from gallery.For this I used
View v= mGallery.childAt(index);
ImageView img = (ImageView) v.findViewById(R.id.img);
But sometimes if that indexed images is not visible that time it is giving
NullPointerException.
How to get the non-visible image from gallery?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您是通过适配器将图像添加到图库中?
如果是这样,您可以使用
getItemAtPosition(index)< /code>
基本上检索您放入适配器中的内容。当然,您需要确保索引有效。
如果您想要选定的项目,您可以使用其他选项来直接访问:
Gallery.getSelectedView()
< /a> 和Gallery.getSelectedItem()< /代码>
I think you are adding the images to the gallery via an adapter?
If so you can use
getItemAtPosition(index)
to basically retrieve what you have put into the adapter. Of course you need to make sure that index is valid.If you want the selected item, you have other options that gives you direct access:
Gallery.getSelectedView()
andGallery.getSelectedItem()
哦,这是一种方法,也是更好的方法,伙计获取图像并显示它们(我在上面的答案中描述过)。
为了解决您的问题,我只能向您展示一些在您的代码中应用的技巧或补丁。
为此,您可以检查空条件。如果您得到空图像,则显示一些默认图像来代替它。
Oh that was one way and better way buddy to get images and show them (I described in my above answer).
To resolve your problem I can only show you some tricks or patches to apply in your code.
For that you can check for null condition. If you are getting null image then show some default image in place of it.