本文介绍了通过获取一个ImageView的Andr​​oid的标签位置设置图像国土资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我利用回收的看法。我有一个淡红色突出显示的布局,这种布局是包含在回收视图中的每个项目。浅红色布局放置在的背景图像。我使用setTag方法标识布局红色按钮的点击。即正常工作当我点击我得到的地位。问题是我想在特定的位置来改变形象。
例如:考虑心脏按钮。我设置了标签上是这样的。

I am making use of recycler view. I have a layout that is highlighted in light red,this layout is included for each item in the recycler view. The light red layout is placed over the background image. I am using setTag method to identify the clicks of the buttons in red layout. That is working properly when i click i get the position. The problem is i want to change the image at specific position.For example : Consider the heart button. I have set a tag on it like this.

heartButton = findViewById(ID);
heartButton.setTag(位置);

现在我使用getTag方法得到的位置。但现在我想改变heartButton的图像在一个特定的位置。有什么样

now i get the position by using the getTag method. But now i want to change the image of the heartButton at the a specific position. Is there something like

heartButton.getTag(位置).setImageResouce(绘制);

如果不是我该如何做到这一点呢。

If not how do i do this then.

推荐答案

我做了一个自定义点击监听器,并更新了二传手类似getter.But这工作,只有当视图已经被移出视图(我认为这是scrapeview)

I made a custom click listener and updated the like in the setter getter.But this works only when the view has been moved out of the view (i think it is the scrapeview)

二传手消气类

public class DemoData {

    int background;
    boolean liked;

    public DemoData(int background) {
        this.background = background;
    }

    public int getBackground() {
        return background;
    }

//    public void setBackground(int background) {
//        this.background = background;
//    }

    public boolean isLiked() {
        return liked;
    }

    public void setLiked(boolean liked) {
        this.liked = liked;
    }
}

在回收视图的onBindViewHolder功能

The onBindViewHolder function of the recycler view

@Override
    public void onBindViewHolder(ViewHolder holder, int position) {


        background = (ImageView) holder.view.findViewById(R.id.image);
        layout = (LinearLayout) holder.view.findViewById(R.id.layout);

        delete = (ImageView) layout.findViewById(R.id.delete);
        lock = (ImageView) layout.findViewById(R.id.lock);


        delete.setTag("delete_"+position);
        lock.setTag("lock_"+position);

        if(Constants.demoDatas.get(position).isLiked()){
            delete.setImageResource(R.drawable.ic_launcher);
        }
        else{
            delete.setImageResource(android.R.drawable.ic_delete);
        }

        delete.setOnClickListener(new CustomClickListener(position));
        lock.setOnClickListener(new CustomClickListener(position));



    }

在自定义点击监听器是如下

The custom click listener is as below

public class CustomClickListener implements View.OnClickListener {

    int position;


    public CustomClickListener(int position) {

        this.position = position;
    }

    @Override
    public void onClick(View v) {

        String tag = (String) v.getTag();
        String identifier[] = tag.split("_");

        // this line saves my state in the Setter Getter Class
        Constants.demoDatas.get(position).setLiked(true);

    }
}

这篇关于通过获取一个ImageView的Andr​​oid的标签位置设置图像国土资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 14:33
查看更多