找到视图中删除的图像

时间:2013-02-13 03:39:30

标签: android android-imageview

我有一个实现OnDragListener的类。我需要检查视图中丢弃的图像。请指导我如何做到这一点。

private class ChoiceDragListener implements OnDragListener {

    @Override
    public boolean onDrag(View v, DragEvent event) {
        switch (event.getAction()) { 
        case DragEvent.ACTION_DROP: 
            View view = (View) event.getLocalState(); 
            view.setVisibility(View.INVISIBLE); 
            ImageView dropTarget = (ImageView) v; 
            ImageView dropped = (ImageView) view; 
            dropTarget.setImageDrawable(dropped.getDrawable());  
            break;
        case DragEvent.ACTION_DRAG_ENDED:
            //no action necessary
            break;
        default:
            break;
        }
        return true;
    }
} 

1 个答案:

答案 0 :(得分:0)

你必须遵循一些步骤:

1)对 MyDragEventListener 类进行objcet。

MyDragEventListener myDragEventListener = new MyDragEventListener();

2)使用此类来定位布局。

view.setOnDragListener(myDragEventListener);

3)

 class MyDragEventListener implements View.OnDragListener {
       @Override
       public boolean onDrag(View v, DragEvent event) {              

              final int action = event.getAction();           
              switch(action) {

              case DragEvent.ACTION_DRAG_STARTED:
                        if (event.getClipDescription()
                          .hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN))
                        {
                         return true; //Accept
                        }
                        else{
                         return false; //reject
                        }

              case DragEvent.ACTION_DRAG_ENTERED:
               return true;

              case DragEvent.ACTION_DRAG_LOCATION:
              return true;

              case DragEvent.ACTION_DRAG_EXITED:
              return true;

             case DragEvent.ACTION_DROP:
                  ClipData.Item item = event.getClipData().getItemAt(0);
                    if(v == view){
                            //put your logic here
                        } 
                       return true;

              case DragEvent.ACTION_DRAG_ENDED:
                  if (event.getResult())
                  {  
                  //forther any updation not require.
                  }                       
                  return true;

              default: //unknown case
                  return false;

              }

             }


        }

导入部分:

case DragEvent.ACTION_DROP:
              ClipData.Item item = event.getClipData().getItemAt(0);
                if(v == view){
                        //put your logic here
                    } 
                   return true;

如果您查询,则发表评论。