如何处理Android Gallery中的位置?

发布于 2024-10-16 19:26:40 字数 1297 浏览 0 评论 0原文

如何处理图库中的位置。我需要更改特定位置的图像背景。我能够在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

日裸衫吸 2024-10-23 19:26:40

在您的活动中创建一个成员变量,例如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 use lastSelected to change the background and then update lastSelected with the newly selected view.

Hope that helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文