当我拖动项目时,我想用另一个词在阴影部分显示文本我想在阴影部分显示项目文本(当用户长按并想放到另一个地方时)!在 startdrag 中,当我调用 myshadow 时,我有数据和项目文本,我无法在阴影框中设置文本(颜色为黄色)。
OnItemLongClickListener listSourceItemLongClickListener = new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> l, View v, int position,
long id) {
// Selected item is passed as item in dragData
ClipData.Item item = new ClipData.Item(lv_arr[position]);
String[] clipDescription = { ClipDescription.MIMETYPE_TEXT_PLAIN };
ClipData dragData = new ClipData((CharSequence) v.getTag(),
clipDescription, item);
DragShadowBuilder myShadow = new MyDragShadowBuilder(v);
v.startDrag(dragData, // ClipData
myShadow, // View.DragShadowBuilder
lv_arr[position], // Object myLocalState
0); // flags
// commentMsg = v.getTag() + " : onLongClick.\n";
// comments.setText(commentMsg);
return true;
}
}
private static class MyDragShadowBuilder extends View.DragShadowBuilder{
private static Drawable shadow;
public MyDragShadowBuilder(View v) {
super(v);
shadow = new ColorDrawable(Color.LTGRAY);
}
@Override
public void onProvideShadowMetrics(Point size, Point touch) {
int width = getView().getWidth();
int height = getView().getHeight();
shadow.setBounds(0, 0, width, height);
size.set(width, height);
touch.set(width / 2, height / 2);
}
@Override
public void onDrawShadow(Canvas canvas) {
shadow.draw(canvas);
}
}