当我拖动项目时我想在阴影部分显示另一个单词中的文本我想在阴影部分中设置文本(当用户长按并想要放到另一个地方时)! 在startdrag中,当我调用myshadow时,我有数据和项目文本我无法在阴影框中设置文本(clor为黄色)。
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);
}
}
答案 0 :(得分:0)
我相信你可以覆盖onDrawShadow(Canvas canvas)
(你实际上已经覆盖了)并使用canvas对象引用来调用方法drawText
传递你想要的文本。
试一试。
答案 1 :(得分:0)
@Override
public void onDrawShadow(Canvas canvas) {
shadow.draw(canvas);
super.onDrawShadow(canvas);
}