如何在android中刷新适配器后在RecyclerView中更改imageview

时间:2017-01-27 12:14:40

标签: android android-recyclerview

您好我正在使用RecyclerView和自定义适配器。当我点击项目更改imageview其他项目我该怎么办?这是我在onBindViewHolder中更改的imageview代码。我会更改时钟图像资源。对不起英文不好

 vi.btn_transfer.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

           // ActiveTransferItem();

            for(int i = 0; i< positionLists.size(); i++)
            {
                if(positionLists.get(i).getLastActionTime().equals("") || positionLists.get(i).getLastActionTime().equals("null"))
                {
                    AppEngine.check_transfer_image = true;
                    vi.img_gpstracking.setBackgroundResource(R.drawable.greencircle);
                    notifyItemChanged(i);
                }
            }


            ((PositionListNewVersion)mContext).getTransferPopUp().setVisibility(View.VISIBLE);
        }
    });

enter image description here

1 个答案:

答案 0 :(得分:0)

使用此类将项目触摸侦听器添加到您的回收站视图。

public class RecyclerTouchListener implements RecyclerView.OnItemTouchListener {

private GestureDetector gestureDetector;
private ClickListener clickListener;

public interface ClickListener {
    void onClick(View view, int position);
}

public RecyclerTouchListener(Context context, final ClickListener clickListener) {
    this.clickListener = clickListener;
    gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return true;
        }
    });
}

@Override
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {

    View child = rv.findChildViewUnder(e.getX(), e.getY());
    if (child != null && clickListener != null && gestureDetector.onTouchEvent(e)) {
        clickListener.onClick(child, rv.getChildAdapterPosition(child));
    }
    return false;
}

@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}

@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

}
}      

通过执行以下操作将此侦听器添加到您的回收站视图:

recyclerView.addOnItemTouchListener(new RecyclerTouchListener(context, new RecyclerTouchListener.ClickListener() {
            @Override
            public void onClick(View view, int position) {
                //Code here to transform the image.
            }
        }));