如何处理Android Gallery中的位置?
如何处理图库中的位置。我需要更改特定位置的图像背景。我能够在 onItemClick 方法中成功更改所选图像的背景图像。但我也需要将旧的所选背景图像更改为非选了一个。
public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
//previouse selected image
//here sometimes it is changing background of another image(which is not a old selected image)
if(mSelectedItemIndex!=-1 && mSelectedItemIndex!=position){
// Object v =mGallery.getItemAtPosition(mSelectedItemIndex);
// View v =imageAdapter.getDropDownView(mSelectedItemIndex,null,null);
// View v =mGallery.getChildAt(mSelectedItemIndex);
View v = (View)view.getChildAt(mSelectedItemIndex);
ImageView imgView = (ImageView) v.findViewById(R.id.adsimage);
// ImageView imgView = (ImageView)v;
// ImageView imgView = (ImageView)arg0.findViewById(R.id.adsimage);
imgView.setBackgroundResource(R.drawable.gallery_unselected_default);
//current selected image
//always this code is working fine.
ImageView imgView = (ImageView)view.findViewById(R.id.adsimage);
imgView.setBackgroundResource(R.drawable.gallery_selected_focused);
}
我在基本适配器中使用了 getItemBackground 主题,但没有用。如果图库从左到右、从右到左滚动,请告诉我如何保留图像位置。如果我一一选择,它工作正常。但是当我选择备用图像时。它不起作用。
How to handle the positions in Gallery.I need to change the background of image at perticular position.Iam able to change the background image of selected image successfully within the onItemClick method.But i need to change the old selected background image also as non-selected one.
public void onItemClick(AdapterView<?> arg0, View view, int position, long arg3) {
//previouse selected image
//here sometimes it is changing background of another image(which is not a old selected image)
if(mSelectedItemIndex!=-1 && mSelectedItemIndex!=position){
// Object v =mGallery.getItemAtPosition(mSelectedItemIndex);
// View v =imageAdapter.getDropDownView(mSelectedItemIndex,null,null);
// View v =mGallery.getChildAt(mSelectedItemIndex);
View v = (View)view.getChildAt(mSelectedItemIndex);
ImageView imgView = (ImageView) v.findViewById(R.id.adsimage);
// ImageView imgView = (ImageView)v;
// ImageView imgView = (ImageView)arg0.findViewById(R.id.adsimage);
imgView.setBackgroundResource(R.drawable.gallery_unselected_default);
//current selected image
//always this code is working fine.
ImageView imgView = (ImageView)view.findViewById(R.id.adsimage);
imgView.setBackgroundResource(R.drawable.gallery_selected_focused);
}
I used getItemBackground theme in base adapter but no use.Please give me how to persist image positions if gallery is scrolling form left to right and right to left.If i select one by one it is working fine.But when i select alternate image.It is not working.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的活动中创建一个成员变量,例如
View lastSelected
,以在选择/单击视图时存储视图。选择/单击新项目时,使用lastSelected
更改背景,然后使用新选择的视图更新lastSelected
。希望有帮助。
Create a member variable eg
View lastSelected
in your activity to store the view when it has been selected/clicked. When a new item is selected/clicked uselastSelected
to change the background and then updatelastSelected
with the newly selected view.Hope that helps.