示例#1
0
  public void setUpDragNDrop() {
    ListView listView = getListView();

    if (listView instanceof DragNDropListView) {
      ((DragNDropListView) listView)
          .setDropListener(
              new DropListener() {
                public void onDrop(View dragged, View replaced) {
                  ListAdapter adapter = getListAdapter();
                  if (adapter instanceof DropListener) {
                    ((DropListener) adapter).onDrop(dragged, replaced);
                    Log.v(TAG, "Invalidating: " + getListView().getClass().getName());
                    fillData();
                  }
                }
              });
      ((DragNDropListView) listView)
          .setDragListener(
              new DragListener() {

                int backgroundColor = 0xe0103010;
                int defaultBackgroundColor;

                public void onDrag(int x, int y, ListView listView) {
                  // TODO Auto-generated method stub
                }

                public void onStartDrag(View itemView) {
                  itemView.setVisibility(View.INVISIBLE);
                  defaultBackgroundColor = itemView.getDrawingCacheBackgroundColor();
                  itemView.setBackgroundColor(backgroundColor);
                  ImageView iv = (ImageView) itemView.findViewById(R.id.image);
                  if (iv != null) iv.setVisibility(View.INVISIBLE);
                }

                public void onStopDrag(View itemView) {
                  itemView.setVisibility(View.VISIBLE);
                  itemView.setBackgroundColor(defaultBackgroundColor);
                  RowidImageView iv = (RowidImageView) itemView.findViewById(R.id.image);
                  if (iv != null) iv.setVisibility(View.VISIBLE);
                }
              });
    } // if it's actually a drag 'n' drop list view!
  } // set up drag and drop