如何检查图像视图中的源是什么?

发布于 2024-12-01 06:08:45 字数 788 浏览 1 评论 0原文

我需要检查按钮单击是否有与列表关联的绘图或其“不可见”。我正在通过查看绘图的来源是否为 @drawable/invisible 或其他内容来进行检查。如果是其他东西,则将其更改为不可见,如果不可见,则将其更改为颜色等...

lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View listview, int position,
                long arg3) {
            ImageView pincolor=(ImageView) listview.findViewById(R.id.ivimtrackingpin);
           // here is where I want to check what the "source" is
            if(pincolor.getResources().equals(R.drawable.invisible)
             //do stuff
            else 
                pincolor.setImageresource(R.drawable.invisible)

        }
    });

我不想只执行 setvisibility =invisible 因为每个列表可以有不同的颜色,并且切换功能将进入内部如果部分。我使用什么方法来确定 imageviews 来源?

谢谢

I need to check on a button click if there is a drawing associated with the list or if its "invisible". I am doing the check by seeing if the source of the drawing is @drawable/invisible or something else. If its something else then change it to invisible, if invisible then change it to a color etc...

lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View listview, int position,
                long arg3) {
            ImageView pincolor=(ImageView) listview.findViewById(R.id.ivimtrackingpin);
           // here is where I want to check what the "source" is
            if(pincolor.getResources().equals(R.drawable.invisible)
             //do stuff
            else 
                pincolor.setImageresource(R.drawable.invisible)

        }
    });

I don't want to just do setvisibility =invisible because there are different colors that each list can be and the switch function will go inside the if part. What method do I use to determine the imageviews source?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

随梦而飞# 2024-12-08 06:08:45

也许您可以利用 ImageView 的 getDrawable() 方法。

/**
* Return the view's drawable, or null if no drawable has been assigned.
*/
public Drawable getDrawable ()

像这样:

ImageView pincolor=(ImageView) listview.findViewById(R.id.ivimtrackingpin);
Drawable drawable = pincolor.getDrawable();
if(drawable  != null) {
    //do stuff with the drawable
} else {
    pincolor.setImageresource(R.drawable.invisible)
}

Maybe you can make use of the ImageView's getDrawable() Method.

/**
* Return the view's drawable, or null if no drawable has been assigned.
*/
public Drawable getDrawable ()

like this:

ImageView pincolor=(ImageView) listview.findViewById(R.id.ivimtrackingpin);
Drawable drawable = pincolor.getDrawable();
if(drawable  != null) {
    //do stuff with the drawable
} else {
    pincolor.setImageresource(R.drawable.invisible)
}
临风闻羌笛 2024-12-08 06:08:45

这将告诉您视图是否不可见:

pincolor.getVisibility()==View.INVISIBLE

This will tell you if the view is invisible:

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